[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" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 47 | #include "net/base/proxy_delegate.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 48 | #include "net/base/proxy_server.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 49 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 50 | #include "net/base/test_completion_callback.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 51 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 52 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 53 | #include "net/base/upload_file_element_reader.h" |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 54 | #include "net/cert/cert_status_flags.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 55 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 56 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 57 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 58 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 59 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 60 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 61 | #include "net/http/http_auth_scheme.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 62 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 63 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 64 | #include "net/http/http_network_session_peer.h" |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 65 | #include "net/http/http_proxy_connect_job.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 66 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 67 | #include "net/http/http_response_info.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 68 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 69 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 70 | #include "net/http/http_stream_factory.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 71 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 72 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 73 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 74 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 75 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 76 | #include "net/log/test_net_log_entry.h" |
| 77 | #include "net/log/test_net_log_util.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 78 | #include "net/proxy_resolution/mock_proxy_resolver.h" |
| 79 | #include "net/proxy_resolution/proxy_config_service_fixed.h" |
| 80 | #include "net/proxy_resolution/proxy_info.h" |
Lily Houghton | ffe89daa0 | 2018-03-09 18:30:03 | [diff] [blame] | 81 | #include "net/proxy_resolution/proxy_resolution_service.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 82 | #include "net/proxy_resolution/proxy_resolver.h" |
| 83 | #include "net/proxy_resolution/proxy_resolver_factory.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 84 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 85 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 86 | #include "net/socket/client_socket_pool_manager.h" |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame^] | 87 | #include "net/socket/connect_job.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 88 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 89 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 90 | #include "net/socket/next_proto.h" |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 91 | #include "net/socket/socket_tag.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 92 | #include "net/socket/socket_test_util.h" |
Matt Menke | 4b412da | 2019-01-25 19:31:12 | [diff] [blame] | 93 | #include "net/socket/socks_connect_job.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 94 | #include "net/socket/ssl_client_socket.h" |
Bence Béky | 94658bf | 2018-05-11 19:22:58 | [diff] [blame] | 95 | #include "net/spdy/spdy_session.h" |
| 96 | #include "net/spdy/spdy_session_pool.h" |
| 97 | #include "net/spdy/spdy_test_util_common.h" |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 98 | #include "net/ssl/default_channel_id_store.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 */, |
| 384 | nullptr /* proxy_delegate */, |
| 385 | nullptr /* http_user_agent_settings */, |
| 386 | SSLClientSocketContext(), |
| 387 | SSLClientSocketContext(), |
| 388 | nullptr /* socket_performance_watcher_factory */, |
| 389 | nullptr /* network_quality_estimator */, |
| 390 | nullptr /* net_log */, |
| 391 | nullptr /* websocket_endpoint_lock_manager */), |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 392 | ssl_(ASYNC, OK), |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 393 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 394 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 395 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 396 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 397 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 398 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 399 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 400 | struct SimpleGetHelperResult { |
| 401 | int rv; |
| 402 | std::string status_line; |
| 403 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 404 | int64_t total_received_bytes; |
| 405 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 406 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 407 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 408 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 409 | }; |
| 410 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 411 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 412 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 413 | base::RunLoop().RunUntilIdle(); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 414 | // Set an initial delay to ensure that the first call to TimeTicks::Now() |
| 415 | // before incrementing the counter does not return a null value. |
| 416 | FastForwardBy(TimeDelta::FromSeconds(1)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 417 | } |
| 418 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 419 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 420 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 421 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 422 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 423 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 424 | PlatformTest::TearDown(); |
[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 | } |
| 428 | |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 429 | void Check100ResponseTiming(bool use_spdy); |
| 430 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 431 | // Either |write_failure| specifies a write failure or |read_failure| |
| 432 | // specifies a read failure when using a reused socket. In either case, the |
| 433 | // failure should cause the network transaction to resend the request, and the |
| 434 | // other argument should be NULL. |
| 435 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 436 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 437 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 438 | // Either |write_failure| specifies a write failure or |read_failure| |
| 439 | // specifies a read failure when using a reused socket. In either case, the |
| 440 | // failure should cause the network transaction to resend the request, and the |
| 441 | // other argument should be NULL. |
| 442 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 443 | const MockRead* read_failure, |
| 444 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 445 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 446 | SimpleGetHelperResult SimpleGetHelperForData( |
| 447 | base::span<StaticSocketDataProvider*> providers) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 448 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 449 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 450 | HttpRequestInfo request; |
| 451 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 452 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 453 | request.traffic_annotation = |
| 454 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 455 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 456 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 457 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 458 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 459 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 460 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 461 | for (auto* provider : providers) { |
| 462 | session_deps_.socket_factory->AddSocketDataProvider(provider); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 463 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 464 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 465 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 466 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 467 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 468 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 469 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 470 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 471 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 472 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 473 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 474 | |
| 475 | // Even in the failure cases that use this function, connections are always |
| 476 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 477 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 478 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 479 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 480 | if (out.rv != OK) |
| 481 | return out; |
| 482 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 483 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 484 | // Can't use ASSERT_* inside helper functions like this, so |
| 485 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 486 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 487 | out.rv = ERR_UNEXPECTED; |
| 488 | return out; |
| 489 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 490 | out.status_line = response->headers->GetStatusLine(); |
| 491 | |
Tsuyoshi Horo | 01faed6 | 2019-02-20 22:11:37 | [diff] [blame] | 492 | EXPECT_EQ("127.0.0.1", response->remote_endpoint.ToStringWithoutPort()); |
| 493 | EXPECT_EQ(80, response->remote_endpoint.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 494 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 495 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 496 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 497 | EXPECT_EQ(got_endpoint, |
| 498 | out.remote_endpoint_after_start.address().size() > 0); |
| 499 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 500 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 501 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 502 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 503 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 504 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 505 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 506 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 507 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 508 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 509 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 510 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 511 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 512 | std::string line; |
| 513 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 514 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 515 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 516 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 517 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 518 | std::string value; |
| 519 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 520 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 521 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 522 | EXPECT_EQ("keep-alive", value); |
| 523 | |
| 524 | std::string response_headers; |
| 525 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 526 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 527 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 528 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 529 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 530 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 531 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 532 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 533 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 534 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 535 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 536 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 537 | SimpleGetHelperResult SimpleGetHelper(base::span<const MockRead> data_reads) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 538 | MockWrite data_writes[] = { |
| 539 | MockWrite("GET / HTTP/1.1\r\n" |
| 540 | "Host: www.example.org\r\n" |
| 541 | "Connection: keep-alive\r\n\r\n"), |
| 542 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 543 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 544 | StaticSocketDataProvider reads(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 545 | StaticSocketDataProvider* data[] = {&reads}; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 546 | SimpleGetHelperResult out = SimpleGetHelperForData(data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 547 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 548 | EXPECT_EQ(CountWriteBytes(data_writes), out.total_sent_bytes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 549 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 550 | } |
| 551 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 552 | void AddSSLSocketData() { |
| 553 | ssl_.next_proto = kProtoHTTP2; |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 554 | ssl_.ssl_info.cert = |
| 555 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 556 | ASSERT_TRUE(ssl_.ssl_info.cert); |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 557 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 558 | } |
| 559 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 560 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 561 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 562 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 563 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 564 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 565 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 566 | |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame^] | 567 | const CommonConnectJobParams dummy_connect_job_params_; |
| 568 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 569 | // These clocks are defined here, even though they're only used in the |
| 570 | // Reporting tests below, since they need to be destroyed after |
| 571 | // |session_deps_|. |
| 572 | base::SimpleTestClock clock_; |
| 573 | base::SimpleTestTickClock tick_clock_; |
| 574 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 575 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 576 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 577 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 578 | |
| 579 | // Original socket limits. Some tests set these. Safest to always restore |
| 580 | // them once each test has been run. |
| 581 | int old_max_group_sockets_; |
| 582 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 583 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 584 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 585 | namespace { |
| 586 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 587 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 588 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 589 | BeforeHeadersSentHandler() |
| 590 | : observed_before_headers_sent_with_proxy_(false), |
| 591 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 592 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 593 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 594 | HttpRequestHeaders* request_headers) { |
| 595 | observed_before_headers_sent_ = true; |
| 596 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 597 | !proxy_info.is_quic()) { |
| 598 | return; |
| 599 | } |
| 600 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 601 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 602 | } |
| 603 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 604 | bool observed_before_headers_sent_with_proxy() const { |
| 605 | return observed_before_headers_sent_with_proxy_; |
| 606 | } |
| 607 | |
| 608 | bool observed_before_headers_sent() const { |
| 609 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | std::string observed_proxy_server_uri() const { |
| 613 | return observed_proxy_server_uri_; |
| 614 | } |
| 615 | |
| 616 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 617 | bool observed_before_headers_sent_with_proxy_; |
| 618 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 619 | std::string observed_proxy_server_uri_; |
| 620 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 621 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 622 | }; |
| 623 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 624 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 625 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 626 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 627 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 628 | const int sizeof_row = strlen(row); |
| 629 | const int num_rows = static_cast<int>( |
| 630 | ceil(static_cast<float>(size) / sizeof_row)); |
| 631 | const int sizeof_data = num_rows * sizeof_row; |
| 632 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 633 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 634 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 635 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 636 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 637 | } |
| 638 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 639 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 640 | uint64_t MockGetMSTime() { |
| 641 | // Tue, 23 May 2017 20:13:07 +0000 |
| 642 | return 131400439870000000; |
| 643 | } |
| 644 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 645 | // Alternative functions that eliminate randomness and dependency on the local |
| 646 | // host name so that the generated NTLM messages are reproducible. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 647 | void MockGenerateRandom(uint8_t* output, size_t n) { |
| 648 | // This is set to 0xaa because the client challenge for testing in |
| 649 | // [MS-NLMP] Section 4.2.1 is 8 bytes of 0xaa. |
| 650 | memset(output, 0xaa, n); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 651 | } |
| 652 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 653 | std::string MockGetHostName() { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 654 | return ntlm::test::kHostnameAscii; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 655 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 656 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 657 | |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame^] | 658 | class CaptureGroupIdTransportSocketPool : public TransportClientSocketPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 659 | public: |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame^] | 660 | explicit CaptureGroupIdTransportSocketPool( |
| 661 | const CommonConnectJobParams* common_connect_job_params) |
| 662 | : TransportClientSocketPool(0, |
| 663 | 0, |
| 664 | base::TimeDelta(), |
| 665 | common_connect_job_params, |
| 666 | nullptr /* ssl_config_service */) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 667 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 668 | const ClientSocketPool::GroupId& last_group_id_received() const { |
| 669 | return last_group_id_; |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 670 | } |
| 671 | |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 672 | bool socket_requested() const { return socket_requested_; } |
| 673 | |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 674 | int RequestSocket( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 675 | const ClientSocketPool::GroupId& group_id, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 676 | const void* socket_params, |
| 677 | RequestPriority priority, |
| 678 | const SocketTag& socket_tag, |
| 679 | ClientSocketPool::RespectLimits respect_limits, |
| 680 | ClientSocketHandle* handle, |
| 681 | CompletionOnceCallback callback, |
| 682 | const ClientSocketPool::ProxyAuthCallback& proxy_auth_callback, |
| 683 | const NetLogWithSource& net_log) override { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 684 | last_group_id_ = group_id; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 685 | socket_requested_ = true; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 686 | return ERR_IO_PENDING; |
| 687 | } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 688 | void CancelRequest(const ClientSocketPool::GroupId& group_id, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 689 | ClientSocketHandle* handle) override {} |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 690 | void ReleaseSocket(const ClientSocketPool::GroupId& group_id, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 691 | std::unique_ptr<StreamSocket> socket, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 692 | int id) override {} |
| 693 | void CloseIdleSockets() override {} |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 694 | void CloseIdleSocketsInGroup( |
| 695 | const ClientSocketPool::GroupId& group_id) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 696 | int IdleSocketCount() const override { return 0; } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 697 | size_t IdleSocketCountInGroup( |
| 698 | const ClientSocketPool::GroupId& group_id) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 699 | return 0; |
| 700 | } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 701 | LoadState GetLoadState(const ClientSocketPool::GroupId& group_id, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 702 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 703 | return LOAD_STATE_IDLE; |
| 704 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 705 | |
| 706 | private: |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 707 | ClientSocketPool::GroupId last_group_id_; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 708 | bool socket_requested_ = false; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 709 | }; |
| 710 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 711 | //----------------------------------------------------------------------------- |
| 712 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 713 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 714 | // configured for common cases. |
| 715 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 716 | if (!auth_challenge) |
| 717 | return false; |
| 718 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 719 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 720 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 721 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 722 | return true; |
| 723 | } |
| 724 | |
| 725 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 726 | if (!auth_challenge) |
| 727 | return false; |
| 728 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 729 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 730 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 731 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 732 | return true; |
| 733 | } |
| 734 | |
| 735 | bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 736 | if (!auth_challenge) |
| 737 | return false; |
| 738 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 739 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 740 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 741 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 742 | return true; |
| 743 | } |
| 744 | |
| 745 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 746 | if (!auth_challenge) |
| 747 | return false; |
| 748 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 749 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 750 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 751 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 752 | return true; |
| 753 | } |
| 754 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 755 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 756 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 757 | if (!auth_challenge) |
| 758 | return false; |
| 759 | EXPECT_FALSE(auth_challenge->is_proxy); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 760 | EXPECT_EQ("https://server", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 761 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 762 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 763 | return true; |
| 764 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 765 | |
| 766 | bool CheckNTLMProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 767 | if (!auth_challenge) |
| 768 | return false; |
| 769 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 770 | EXPECT_EQ("http://server", auth_challenge->challenger.Serialize()); |
| 771 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 772 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
| 773 | return true; |
| 774 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 775 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 776 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 777 | } // namespace |
| 778 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 779 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 780 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 781 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 782 | } |
| 783 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 784 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 785 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 786 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 787 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 788 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 789 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 790 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 791 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 792 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 793 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 794 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 795 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 796 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 797 | |
| 798 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 802 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 803 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 804 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 805 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 806 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 807 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 808 | EXPECT_THAT(out.rv, IsOk()); |
| 809 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 810 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 811 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 812 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 813 | } |
| 814 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 815 | // Response with no status line, and a weird port. Should fail by default. |
| 816 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 817 | MockRead data_reads[] = { |
| 818 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 819 | }; |
| 820 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 821 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 822 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 823 | |
| 824 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 825 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 826 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 827 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 828 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 829 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 830 | request.method = "GET"; |
| 831 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 832 | request.traffic_annotation = |
| 833 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 834 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 835 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 836 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 837 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 838 | } |
| 839 | |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 840 | // Tests that request info can be destroyed after the headers phase is complete. |
| 841 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoReadDestroyRequestInfo) { |
| 842 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 843 | auto trans = |
| 844 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 845 | |
| 846 | MockRead data_reads[] = { |
| 847 | MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Connection: keep-alive\r\n"), |
| 848 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, 0), |
| 849 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 850 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 851 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 852 | |
| 853 | TestCompletionCallback callback; |
| 854 | |
| 855 | { |
| 856 | auto request = std::make_unique<HttpRequestInfo>(); |
| 857 | request->method = "GET"; |
| 858 | request->url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 859 | request->traffic_annotation = |
| 860 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 861 | |
| 862 | int rv = |
| 863 | trans->Start(request.get(), callback.callback(), NetLogWithSource()); |
| 864 | |
| 865 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 866 | } // Let request info be destroyed. |
| 867 | |
| 868 | trans.reset(); |
| 869 | } |
| 870 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 871 | // Response with no status line, and a weird port. Option to allow weird ports |
| 872 | // enabled. |
| 873 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 874 | MockRead data_reads[] = { |
| 875 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 876 | }; |
| 877 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 878 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 879 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 880 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 881 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 882 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 883 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 884 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 885 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 886 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 887 | request.method = "GET"; |
| 888 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 889 | request.traffic_annotation = |
| 890 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 891 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 892 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 893 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 894 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 895 | |
| 896 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 897 | ASSERT_TRUE(info->headers); |
| 898 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 899 | |
| 900 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 901 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 902 | } |
| 903 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 904 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 905 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 906 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 907 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 908 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 909 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 910 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 911 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 912 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 913 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 914 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 915 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 919 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 920 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 921 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 922 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 923 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 924 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 925 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 926 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 927 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 928 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 929 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 933 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 934 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 935 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 936 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 937 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 938 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 939 | EXPECT_THAT(out.rv, IsOk()); |
| 940 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 941 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 942 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 943 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 947 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 948 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 949 | MockRead("\n"), |
| 950 | MockRead("\n"), |
| 951 | MockRead("Q"), |
| 952 | MockRead("J"), |
| 953 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 954 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 955 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 956 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 957 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 958 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 959 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 960 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 961 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 965 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 966 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 967 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 968 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 969 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 970 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 971 | EXPECT_THAT(out.rv, IsOk()); |
| 972 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 973 | EXPECT_EQ("HTT", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 974 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 975 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 976 | } |
| 977 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 978 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 979 | // persistent connection. The response should still terminate since a 204 |
| 980 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 981 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 982 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 983 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 984 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 985 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 986 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 987 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 988 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 989 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 990 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 991 | EXPECT_EQ("", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 992 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 993 | int64_t response_size = reads_size - strlen(junk); |
| 994 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 995 | } |
| 996 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 997 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 998 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 999 | std::string final_chunk = "0\r\n\r\n"; |
| 1000 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 1001 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1002 | MockRead data_reads[] = { |
| 1003 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 1004 | MockRead("5\r\nHello\r\n"), |
| 1005 | MockRead("1\r\n"), |
| 1006 | MockRead(" \r\n"), |
| 1007 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1008 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1009 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1010 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1011 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1012 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1013 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1014 | EXPECT_EQ("Hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1015 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1016 | int64_t response_size = reads_size - extra_data.size(); |
| 1017 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1018 | } |
| 1019 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1020 | // Next tests deal with http://crbug.com/56344. |
| 1021 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1022 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1023 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 1024 | MockRead data_reads[] = { |
| 1025 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1026 | MockRead("Content-Length: 10\r\n"), |
| 1027 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1028 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1029 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1030 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1031 | } |
| 1032 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1033 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1034 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 1035 | MockRead data_reads[] = { |
| 1036 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1037 | MockRead("Content-Length: 5\r\n"), |
| 1038 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1039 | MockRead("Hello"), |
| 1040 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1041 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1042 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1043 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1044 | EXPECT_EQ("Hello", out.response_data); |
| 1045 | } |
| 1046 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1047 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1048 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1049 | // More than 2 dupes. |
| 1050 | { |
| 1051 | MockRead data_reads[] = { |
| 1052 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1053 | MockRead("Content-Length: 5\r\n"), |
| 1054 | MockRead("Content-Length: 5\r\n"), |
| 1055 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1056 | MockRead("Hello"), |
| 1057 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1058 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1059 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1060 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1061 | EXPECT_EQ("Hello", out.response_data); |
| 1062 | } |
| 1063 | // HTTP/1.0 |
| 1064 | { |
| 1065 | MockRead data_reads[] = { |
| 1066 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1067 | MockRead("Content-Length: 5\r\n"), |
| 1068 | MockRead("Content-Length: 5\r\n"), |
| 1069 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1070 | MockRead("Hello"), |
| 1071 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1072 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1073 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1074 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1075 | EXPECT_EQ("Hello", out.response_data); |
| 1076 | } |
| 1077 | // 2 dupes and one mismatched. |
| 1078 | { |
| 1079 | MockRead data_reads[] = { |
| 1080 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1081 | MockRead("Content-Length: 10\r\n"), |
| 1082 | MockRead("Content-Length: 10\r\n"), |
| 1083 | MockRead("Content-Length: 5\r\n\r\n"), |
| 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, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1087 | } |
| 1088 | } |
| 1089 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1090 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1091 | MultipleContentLengthHeadersTransferEncoding) { |
| 1092 | MockRead data_reads[] = { |
| 1093 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1094 | MockRead("Content-Length: 666\r\n"), |
| 1095 | MockRead("Content-Length: 1337\r\n"), |
| 1096 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1097 | MockRead("5\r\nHello\r\n"), |
| 1098 | MockRead("1\r\n"), |
| 1099 | MockRead(" \r\n"), |
| 1100 | MockRead("5\r\nworld\r\n"), |
| 1101 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1102 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1103 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1104 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1105 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1106 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1107 | EXPECT_EQ("Hello world", out.response_data); |
| 1108 | } |
| 1109 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1110 | // Next tests deal with http://crbug.com/98895. |
| 1111 | |
| 1112 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1113 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1114 | MockRead data_reads[] = { |
| 1115 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1116 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1117 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1118 | MockRead("Hello"), |
| 1119 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1120 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1121 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1122 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1123 | EXPECT_EQ("Hello", out.response_data); |
| 1124 | } |
| 1125 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1126 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1127 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1128 | MockRead data_reads[] = { |
| 1129 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1130 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1131 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1132 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1133 | MockRead("Hello"), |
| 1134 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1135 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1136 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1137 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1138 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1142 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1143 | MockRead data_reads[] = { |
| 1144 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1145 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1146 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1147 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1148 | MockRead("Hello"), |
| 1149 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1150 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1151 | EXPECT_THAT(out.rv, |
| 1152 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1153 | } |
| 1154 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1155 | // Checks that two identical Location headers result in no error. |
| 1156 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1157 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1158 | MockRead data_reads[] = { |
| 1159 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1160 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1161 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1162 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1163 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1164 | }; |
| 1165 | |
| 1166 | HttpRequestInfo request; |
| 1167 | request.method = "GET"; |
| 1168 | request.url = GURL("http://redirect.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1169 | request.traffic_annotation = |
| 1170 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1171 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1172 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1173 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1174 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1175 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1176 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1177 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1178 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1179 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1180 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1181 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1182 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1183 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1184 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1185 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1186 | ASSERT_TRUE(response); |
| 1187 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1188 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1189 | std::string url; |
| 1190 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1191 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1192 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1193 | } |
| 1194 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1195 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1196 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1197 | MockRead data_reads[] = { |
| 1198 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1199 | MockRead("Location: http://good.com/\r\n"), |
| 1200 | MockRead("Location: http://evil.com/\r\n"), |
| 1201 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1202 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1203 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1204 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1205 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1206 | } |
| 1207 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1208 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1209 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1210 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1211 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1212 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1213 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1214 | request.traffic_annotation = |
| 1215 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1216 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1217 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1218 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1219 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1220 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1221 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1222 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1223 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1224 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1225 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1226 | "Host: www.example.org\r\n" |
| 1227 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1228 | }; |
| 1229 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1230 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1231 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1232 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1233 | // No response body because the test stops reading here. |
| 1234 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1235 | }; |
| 1236 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1237 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1238 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1239 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1240 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1241 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1242 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1243 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1244 | |
| 1245 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1246 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1247 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1248 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1249 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1250 | |
| 1251 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1252 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1253 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1254 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1255 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1256 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1257 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1258 | |
| 1259 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1260 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1261 | bool has_server_header = response->headers->EnumerateHeader( |
| 1262 | &iter, "Server", &server_header); |
| 1263 | EXPECT_TRUE(has_server_header); |
| 1264 | EXPECT_EQ("Blah", server_header); |
| 1265 | |
| 1266 | // Reading should give EOF right away, since there is no message body |
| 1267 | // (despite non-zero content-length). |
| 1268 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1269 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1270 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1271 | EXPECT_EQ("", response_data); |
| 1272 | } |
| 1273 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1274 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1275 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1276 | |
| 1277 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1278 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1279 | MockRead("hello"), |
| 1280 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1281 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1282 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1283 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1284 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1285 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1286 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1287 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1288 | "hello", "world" |
| 1289 | }; |
| 1290 | |
| 1291 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1292 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1293 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1294 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1295 | request.traffic_annotation = |
| 1296 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1297 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1298 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1299 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1300 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1301 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1302 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1303 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1304 | |
| 1305 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1306 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1307 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1308 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1309 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1310 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1311 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1312 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1313 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1314 | |
| 1315 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1316 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1317 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1318 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1319 | } |
| 1320 | } |
| 1321 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1322 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1323 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1324 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1325 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1326 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1327 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1328 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1329 | request.method = "POST"; |
| 1330 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1331 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1332 | request.traffic_annotation = |
| 1333 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1334 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1335 | // Check the upload progress returned before initialization is correct. |
| 1336 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1337 | EXPECT_EQ(0u, progress.size()); |
| 1338 | EXPECT_EQ(0u, progress.position()); |
| 1339 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1340 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1341 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1342 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1343 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1344 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1345 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1346 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1347 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1348 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1349 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1350 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1351 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1352 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1353 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1354 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1355 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1356 | |
| 1357 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1358 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1359 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1360 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1361 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1362 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1363 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1364 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1365 | |
| 1366 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1367 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1368 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1369 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1370 | } |
| 1371 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1372 | // This test is almost the same as Ignores100 above, but the response contains |
| 1373 | // 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] | 1374 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1375 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1376 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1377 | request.method = "GET"; |
| 1378 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1379 | request.traffic_annotation = |
| 1380 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1381 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1382 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1383 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1384 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1385 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1386 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1387 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1388 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1389 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1390 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1391 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1392 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1393 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1394 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1395 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1396 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1397 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1398 | |
| 1399 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1400 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1401 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1402 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1403 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1404 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1405 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1406 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1407 | |
| 1408 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1409 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1410 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1411 | EXPECT_EQ("hello world", response_data); |
| 1412 | } |
| 1413 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1414 | TEST_F(HttpNetworkTransactionTest, LoadTimingMeasuresTimeToFirstByteForHttp) { |
| 1415 | static const base::TimeDelta kDelayAfterFirstByte = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1416 | base::TimeDelta::FromMilliseconds(10); |
| 1417 | |
| 1418 | HttpRequestInfo request; |
| 1419 | request.method = "GET"; |
| 1420 | request.url = GURL("http://www.foo.com/"); |
| 1421 | request.traffic_annotation = |
| 1422 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1423 | |
| 1424 | std::vector<MockWrite> data_writes = { |
| 1425 | MockWrite(ASYNC, 0, |
| 1426 | "GET / HTTP/1.1\r\n" |
| 1427 | "Host: www.foo.com\r\n" |
| 1428 | "Connection: keep-alive\r\n\r\n"), |
| 1429 | }; |
| 1430 | |
| 1431 | std::vector<MockRead> data_reads = { |
| 1432 | // Write one byte of the status line, followed by a pause. |
| 1433 | MockRead(ASYNC, 1, "H"), |
| 1434 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1435 | MockRead(ASYNC, 3, "TTP/1.1 200 OK\r\n\r\n"), |
| 1436 | MockRead(ASYNC, 4, "hello world"), |
| 1437 | MockRead(SYNCHRONOUS, OK, 5), |
| 1438 | }; |
| 1439 | |
| 1440 | SequencedSocketData data(data_reads, data_writes); |
| 1441 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1442 | |
| 1443 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1444 | |
| 1445 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1446 | |
| 1447 | TestCompletionCallback callback; |
| 1448 | |
| 1449 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1450 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1451 | |
| 1452 | data.RunUntilPaused(); |
| 1453 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1454 | FastForwardBy(kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1455 | data.Resume(); |
| 1456 | |
| 1457 | rv = callback.WaitForResult(); |
| 1458 | EXPECT_THAT(rv, IsOk()); |
| 1459 | |
| 1460 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1461 | ASSERT_TRUE(response); |
| 1462 | |
| 1463 | EXPECT_TRUE(response->headers); |
| 1464 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1465 | |
| 1466 | LoadTimingInfo load_timing_info; |
| 1467 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1468 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1469 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1470 | // Ensure we didn't include the delay in the TTFB time. |
| 1471 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1472 | load_timing_info.connect_timing.connect_end); |
| 1473 | // Ensure that the mock clock advanced at all. |
| 1474 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1475 | kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1476 | |
| 1477 | std::string response_data; |
| 1478 | rv = ReadTransaction(&trans, &response_data); |
| 1479 | EXPECT_THAT(rv, IsOk()); |
| 1480 | EXPECT_EQ("hello world", response_data); |
| 1481 | } |
| 1482 | |
| 1483 | // Tests that the time-to-first-byte reported in a transaction's load timing |
| 1484 | // info uses the first response, even if 1XX/informational. |
| 1485 | void HttpNetworkTransactionTest::Check100ResponseTiming(bool use_spdy) { |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1486 | static const base::TimeDelta kDelayAfter100Response = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1487 | base::TimeDelta::FromMilliseconds(10); |
| 1488 | |
| 1489 | HttpRequestInfo request; |
| 1490 | request.method = "GET"; |
| 1491 | request.url = GURL("https://www.foo.com/"); |
| 1492 | request.traffic_annotation = |
| 1493 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1494 | |
| 1495 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 1496 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 1497 | |
| 1498 | std::vector<MockWrite> data_writes; |
| 1499 | std::vector<MockRead> data_reads; |
| 1500 | |
| 1501 | spdy::SpdySerializedFrame spdy_req( |
| 1502 | spdy_util_.ConstructSpdyGet(request.url.spec().c_str(), 1, LOWEST)); |
| 1503 | |
| 1504 | spdy::SpdyHeaderBlock spdy_resp1_headers; |
| 1505 | spdy_resp1_headers[spdy::kHttp2StatusHeader] = "100"; |
| 1506 | spdy::SpdySerializedFrame spdy_resp1( |
| 1507 | spdy_util_.ConstructSpdyReply(1, spdy_resp1_headers.Clone())); |
| 1508 | spdy::SpdySerializedFrame spdy_resp2( |
| 1509 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 1510 | spdy::SpdySerializedFrame spdy_data( |
| 1511 | spdy_util_.ConstructSpdyDataFrame(1, "hello world", true)); |
| 1512 | |
| 1513 | if (use_spdy) { |
| 1514 | ssl.next_proto = kProtoHTTP2; |
| 1515 | |
| 1516 | data_writes = {CreateMockWrite(spdy_req, 0)}; |
| 1517 | |
| 1518 | data_reads = { |
| 1519 | CreateMockRead(spdy_resp1, 1), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1520 | CreateMockRead(spdy_resp2, 3), CreateMockRead(spdy_data, 4), |
| 1521 | MockRead(SYNCHRONOUS, OK, 5), |
| 1522 | }; |
| 1523 | } else { |
| 1524 | data_writes = { |
| 1525 | MockWrite(ASYNC, 0, |
| 1526 | "GET / HTTP/1.1\r\n" |
| 1527 | "Host: www.foo.com\r\n" |
| 1528 | "Connection: keep-alive\r\n\r\n"), |
| 1529 | }; |
| 1530 | |
| 1531 | data_reads = { |
| 1532 | MockRead(ASYNC, 1, "HTTP/1.1 100 Continue\r\n\r\n"), |
| 1533 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1534 | |
| 1535 | MockRead(ASYNC, 3, "HTTP/1.1 200 OK\r\n\r\n"), |
| 1536 | MockRead(ASYNC, 4, "hello world"), |
| 1537 | MockRead(SYNCHRONOUS, OK, 5), |
| 1538 | }; |
| 1539 | } |
| 1540 | |
| 1541 | SequencedSocketData data(data_reads, data_writes); |
| 1542 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1543 | |
| 1544 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1545 | |
| 1546 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1547 | |
| 1548 | TestCompletionCallback callback; |
| 1549 | |
| 1550 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1551 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1552 | |
| 1553 | data.RunUntilPaused(); |
| 1554 | // We should now have parsed the 100 response and hit ERR_IO_PENDING. Insert |
| 1555 | // the delay before parsing the 200 response. |
| 1556 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1557 | FastForwardBy(kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1558 | data.Resume(); |
| 1559 | |
| 1560 | rv = callback.WaitForResult(); |
| 1561 | EXPECT_THAT(rv, IsOk()); |
| 1562 | |
| 1563 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1564 | ASSERT_TRUE(response); |
| 1565 | |
| 1566 | LoadTimingInfo load_timing_info; |
| 1567 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1568 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1569 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1570 | // Ensure we didn't include the delay in the TTFB time. |
| 1571 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1572 | load_timing_info.connect_timing.connect_end); |
| 1573 | // Ensure that the mock clock advanced at all. |
| 1574 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1575 | kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1576 | |
| 1577 | std::string response_data; |
| 1578 | rv = ReadTransaction(&trans, &response_data); |
| 1579 | EXPECT_THAT(rv, IsOk()); |
| 1580 | EXPECT_EQ("hello world", response_data); |
| 1581 | } |
| 1582 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1583 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForHttp) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1584 | Check100ResponseTiming(false /* use_spdy */); |
| 1585 | } |
| 1586 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1587 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForSpdy) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1588 | Check100ResponseTiming(true /* use_spdy */); |
| 1589 | } |
| 1590 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1591 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1592 | HttpRequestInfo request; |
| 1593 | request.method = "POST"; |
| 1594 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1595 | request.traffic_annotation = |
| 1596 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1597 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1598 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1599 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1600 | |
| 1601 | MockRead data_reads[] = { |
| 1602 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1603 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1604 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1605 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1606 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1607 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1608 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1609 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1610 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1611 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1612 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1613 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1614 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1615 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1616 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1617 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1618 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1619 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1620 | } |
| 1621 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1622 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1623 | HttpRequestInfo request; |
| 1624 | request.method = "POST"; |
| 1625 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1626 | request.traffic_annotation = |
| 1627 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1628 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1629 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1630 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1631 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1632 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1633 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1634 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1635 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1636 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1637 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1638 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1639 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1640 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1641 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1642 | |
| 1643 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1644 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1645 | } |
| 1646 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1647 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1648 | const MockWrite* write_failure, |
| 1649 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1650 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1651 | request.method = "GET"; |
| 1652 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1653 | request.traffic_annotation = |
| 1654 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1655 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1656 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1657 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1658 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1659 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1660 | // Written data for successfully sending both requests. |
| 1661 | MockWrite data1_writes[] = { |
| 1662 | MockWrite("GET / HTTP/1.1\r\n" |
| 1663 | "Host: www.foo.com\r\n" |
| 1664 | "Connection: keep-alive\r\n\r\n"), |
| 1665 | MockWrite("GET / HTTP/1.1\r\n" |
| 1666 | "Host: www.foo.com\r\n" |
| 1667 | "Connection: keep-alive\r\n\r\n") |
| 1668 | }; |
| 1669 | |
| 1670 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1671 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1672 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1673 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1674 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1675 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1676 | |
| 1677 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1678 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1679 | data1_writes[1] = *write_failure; |
| 1680 | } else { |
| 1681 | ASSERT_TRUE(read_failure); |
| 1682 | data1_reads[2] = *read_failure; |
| 1683 | } |
| 1684 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1685 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1686 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1687 | |
| 1688 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1689 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1690 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1691 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1692 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1693 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1694 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1695 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1696 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1697 | "hello", "world" |
| 1698 | }; |
| 1699 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1700 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1701 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1702 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1703 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1704 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1705 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1706 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1707 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1708 | |
| 1709 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1710 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1711 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1712 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1713 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1714 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1715 | if (i == 0) { |
| 1716 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1717 | } else { |
| 1718 | // The second request should be using a new socket. |
| 1719 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1720 | } |
| 1721 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1722 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1723 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1724 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1725 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1726 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1727 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1728 | |
| 1729 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1730 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1731 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1732 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1733 | } |
| 1734 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1735 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1736 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1737 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1738 | const MockRead* read_failure, |
| 1739 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1740 | HttpRequestInfo request; |
| 1741 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1742 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1743 | request.traffic_annotation = |
| 1744 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1745 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1746 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1747 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1748 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1749 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1750 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1751 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1752 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1753 | ssl1.next_proto = kProtoHTTP2; |
| 1754 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1755 | } |
| 1756 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1757 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1758 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1759 | // SPDY versions of the request and response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1760 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1761 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1762 | spdy::SpdySerializedFrame spdy_response( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1763 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1764 | spdy::SpdySerializedFrame spdy_data( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 1765 | spdy_util_.ConstructSpdyDataFrame(1, "hello", true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1766 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1767 | // HTTP/1.1 versions of the request and response. |
| 1768 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1769 | "Host: www.foo.com\r\n" |
| 1770 | "Connection: keep-alive\r\n\r\n"; |
| 1771 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1772 | const char kHttpData[] = "hello"; |
| 1773 | |
| 1774 | std::vector<MockRead> data1_reads; |
| 1775 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1776 | if (write_failure) { |
| 1777 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1778 | data1_writes.push_back(*write_failure); |
| 1779 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1780 | } else { |
| 1781 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1782 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1783 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1784 | } else { |
| 1785 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1786 | } |
| 1787 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1788 | } |
| 1789 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1790 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1791 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1792 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1793 | std::vector<MockRead> data2_reads; |
| 1794 | std::vector<MockWrite> data2_writes; |
| 1795 | |
| 1796 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1797 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1798 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1799 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1800 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1801 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1802 | } else { |
| 1803 | data2_writes.push_back( |
| 1804 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1805 | |
| 1806 | data2_reads.push_back( |
| 1807 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1808 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1809 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1810 | } |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1811 | SequencedSocketData data2(data2_reads, data2_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1812 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1813 | |
| 1814 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1815 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1816 | // Wait for the preconnect to complete. |
| 1817 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1818 | base::RunLoop().RunUntilIdle(); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 1819 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1820 | |
| 1821 | // Make the request. |
| 1822 | TestCompletionCallback callback; |
| 1823 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1824 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1825 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1826 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1827 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1828 | |
| 1829 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1830 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1831 | |
| 1832 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1833 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1834 | TestLoadTimingNotReused( |
| 1835 | load_timing_info, |
| 1836 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1837 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1838 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1839 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1840 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1841 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1842 | if (response->was_fetched_via_spdy) { |
| 1843 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1844 | } else { |
| 1845 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1846 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1847 | |
| 1848 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1849 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1850 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1851 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1852 | } |
| 1853 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1854 | // Test that we do not retry indefinitely when a server sends an error like |
| 1855 | // ERR_SPDY_PING_FAILED, ERR_SPDY_SERVER_REFUSED_STREAM, |
| 1856 | // ERR_QUIC_HANDSHAKE_FAILED or ERR_QUIC_PROTOCOL_ERROR. |
| 1857 | TEST_F(HttpNetworkTransactionTest, FiniteRetriesOnIOError) { |
| 1858 | HttpRequestInfo request; |
| 1859 | request.method = "GET"; |
| 1860 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1861 | request.traffic_annotation = |
| 1862 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1863 | |
| 1864 | // Check whether we give up after the third try. |
| 1865 | |
| 1866 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1867 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1868 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1869 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1870 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1871 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1872 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1873 | |
| 1874 | // Three go away responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1875 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1876 | StaticSocketDataProvider data2(data_read1, data_write); |
| 1877 | StaticSocketDataProvider data3(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1878 | |
| 1879 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1880 | AddSSLSocketData(); |
| 1881 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1882 | AddSSLSocketData(); |
| 1883 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1884 | AddSSLSocketData(); |
| 1885 | |
| 1886 | TestCompletionCallback callback; |
| 1887 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1888 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1889 | |
| 1890 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1891 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1892 | |
| 1893 | rv = callback.WaitForResult(); |
| 1894 | EXPECT_THAT(rv, IsError(ERR_SPDY_SERVER_REFUSED_STREAM)); |
| 1895 | } |
| 1896 | |
| 1897 | TEST_F(HttpNetworkTransactionTest, RetryTwiceOnIOError) { |
| 1898 | HttpRequestInfo request; |
| 1899 | request.method = "GET"; |
| 1900 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1901 | request.traffic_annotation = |
| 1902 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1903 | |
| 1904 | // Check whether we try atleast thrice before giving up. |
| 1905 | |
| 1906 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1907 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1908 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1909 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1910 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1911 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1912 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1913 | |
| 1914 | // Construct a non error HTTP2 response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1915 | spdy::SpdySerializedFrame spdy_response_no_error( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1916 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1917 | spdy::SpdySerializedFrame spdy_data( |
| 1918 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1919 | MockRead data_read2[] = {CreateMockRead(spdy_response_no_error, 1), |
| 1920 | CreateMockRead(spdy_data, 2)}; |
| 1921 | |
| 1922 | // Two error responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1923 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1924 | StaticSocketDataProvider data2(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1925 | // Followed by a success response. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1926 | SequencedSocketData data3(data_read2, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1927 | |
| 1928 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1929 | AddSSLSocketData(); |
| 1930 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1931 | AddSSLSocketData(); |
| 1932 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1933 | AddSSLSocketData(); |
| 1934 | |
| 1935 | TestCompletionCallback callback; |
| 1936 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1937 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1938 | |
| 1939 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1940 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1941 | |
| 1942 | rv = callback.WaitForResult(); |
| 1943 | EXPECT_THAT(rv, IsOk()); |
| 1944 | } |
| 1945 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1946 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1947 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1948 | KeepAliveConnectionResendRequestTest(&write_failure, nullptr); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1949 | } |
| 1950 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1951 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1952 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1953 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1954 | } |
| 1955 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1956 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1957 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1958 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1959 | } |
| 1960 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1961 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1962 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1963 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1964 | MockRead read_failure(SYNCHRONOUS, |
| 1965 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1966 | "Connection: Keep-Alive\r\n" |
| 1967 | "Content-Length: 6\r\n\r\n" |
| 1968 | "Pickle"); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1969 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1970 | } |
| 1971 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1972 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1973 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1974 | PreconnectErrorResendRequestTest(&write_failure, nullptr, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1975 | } |
| 1976 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1977 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1978 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1979 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1980 | } |
| 1981 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1982 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1983 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1984 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1985 | } |
| 1986 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1987 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1988 | MockRead read_failure(ASYNC, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1989 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1990 | } |
| 1991 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1992 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1993 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1994 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1995 | MockRead read_failure(SYNCHRONOUS, |
| 1996 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1997 | "Connection: Keep-Alive\r\n" |
| 1998 | "Content-Length: 6\r\n\r\n" |
| 1999 | "Pickle"); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2000 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
| 2001 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2002 | } |
| 2003 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2004 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2005 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2006 | PreconnectErrorResendRequestTest(&write_failure, nullptr, true); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2007 | } |
| 2008 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2009 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2010 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2011 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2012 | } |
| 2013 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2014 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2015 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2016 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2017 | } |
| 2018 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2019 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2020 | MockRead read_failure(ASYNC, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2021 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2022 | } |
| 2023 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2024 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2025 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2026 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2027 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2028 | request.traffic_annotation = |
| 2029 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2030 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2031 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2032 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2033 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2034 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2035 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2036 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2037 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2038 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2039 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2040 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2041 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2042 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2043 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2044 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2045 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2046 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2047 | |
| 2048 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2049 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2050 | |
| 2051 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2052 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2053 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2054 | } |
| 2055 | |
| 2056 | // What do various browsers do when the server closes a non-keepalive |
| 2057 | // connection without sending any response header or body? |
| 2058 | // |
| 2059 | // IE7: error page |
| 2060 | // Safari 3.1.2 (Windows): error page |
| 2061 | // Firefox 3.0.1: blank page |
| 2062 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2063 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 2064 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2065 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2066 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2067 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2068 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2069 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2070 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2071 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2072 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2073 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2074 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 2075 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2076 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 2077 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 2078 | // destructor in such situations. |
| 2079 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2080 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2081 | HttpRequestInfo request; |
| 2082 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2083 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2084 | request.traffic_annotation = |
| 2085 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2086 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2087 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2088 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2089 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2090 | |
| 2091 | MockRead data_reads[] = { |
| 2092 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2093 | MockRead("Connection: keep-alive\r\n"), |
| 2094 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2095 | MockRead("hello"), |
| 2096 | MockRead(SYNCHRONOUS, 0), |
| 2097 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2098 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2099 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2100 | |
| 2101 | TestCompletionCallback callback; |
| 2102 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2103 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2104 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2105 | |
| 2106 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2107 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2108 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2109 | scoped_refptr<IOBufferWithSize> io_buf = |
| 2110 | base::MakeRefCounted<IOBufferWithSize>(100); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2111 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2112 | if (rv == ERR_IO_PENDING) |
| 2113 | rv = callback.WaitForResult(); |
| 2114 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2115 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2116 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2117 | |
| 2118 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2119 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2120 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2121 | } |
| 2122 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2123 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2124 | HttpRequestInfo request; |
| 2125 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2126 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2127 | request.traffic_annotation = |
| 2128 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2129 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2130 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2131 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2132 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2133 | |
| 2134 | MockRead data_reads[] = { |
| 2135 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2136 | MockRead("Connection: keep-alive\r\n"), |
| 2137 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2138 | MockRead(SYNCHRONOUS, 0), |
| 2139 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2140 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2141 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2142 | |
| 2143 | TestCompletionCallback callback; |
| 2144 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2145 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2146 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2147 | |
| 2148 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2149 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2150 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2151 | scoped_refptr<IOBufferWithSize> io_buf( |
| 2152 | base::MakeRefCounted<IOBufferWithSize>(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2153 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2154 | if (rv == ERR_IO_PENDING) |
| 2155 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2156 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2157 | |
| 2158 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2159 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2160 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2161 | } |
| 2162 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2163 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 2164 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2165 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2166 | HttpRequestInfo request; |
| 2167 | request.method = "GET"; |
| 2168 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2169 | request.traffic_annotation = |
| 2170 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2171 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2172 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2173 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2174 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2175 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2176 | const char* request_data = |
| 2177 | "GET / HTTP/1.1\r\n" |
| 2178 | "Host: www.foo.com\r\n" |
| 2179 | "Connection: keep-alive\r\n\r\n"; |
| 2180 | MockWrite data_writes[] = { |
| 2181 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 2182 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 2183 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 2184 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 2185 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 2186 | }; |
| 2187 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2188 | // Note that because all these reads happen in the same |
| 2189 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 2190 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2191 | MockRead data_reads[] = { |
| 2192 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 2193 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 2194 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 2195 | MockRead(ASYNC, 7, |
| 2196 | "HTTP/1.1 302 Found\r\n" |
| 2197 | "Content-Length: 0\r\n\r\n"), |
| 2198 | MockRead(ASYNC, 9, |
| 2199 | "HTTP/1.1 302 Found\r\n" |
| 2200 | "Content-Length: 5\r\n\r\n" |
| 2201 | "hello"), |
| 2202 | MockRead(ASYNC, 11, |
| 2203 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2204 | "Content-Length: 0\r\n\r\n"), |
| 2205 | MockRead(ASYNC, 13, |
| 2206 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2207 | "Content-Length: 5\r\n\r\n" |
| 2208 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2209 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2210 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 2211 | // the set_busy_before_sync_reads(true) call, while the |
| 2212 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 2213 | // reuseable. See http://crbug.com/544255. |
| 2214 | MockRead(ASYNC, 15, |
| 2215 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2216 | "Content-Length: 5\r\n\r\n"), |
| 2217 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2218 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2219 | MockRead(ASYNC, 18, |
| 2220 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2221 | "Content-Length: 5\r\n\r\n" |
| 2222 | "he"), |
| 2223 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 2224 | |
| 2225 | // The body of the final request is actually read. |
| 2226 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 2227 | MockRead(ASYNC, 22, "hello"), |
| 2228 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2229 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2230 | data.set_busy_before_sync_reads(true); |
| 2231 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2232 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2233 | const int kNumUnreadBodies = base::size(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2234 | std::string response_lines[kNumUnreadBodies]; |
| 2235 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 2236 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2237 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2238 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2239 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2240 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2241 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2242 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2243 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2244 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2245 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2246 | LoadTimingInfo load_timing_info; |
| 2247 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2248 | if (i == 0) { |
| 2249 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2250 | first_socket_log_id = load_timing_info.socket_log_id; |
| 2251 | } else { |
| 2252 | TestLoadTimingReused(load_timing_info); |
| 2253 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 2254 | } |
| 2255 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2256 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2257 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2258 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2259 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2260 | response_lines[i] = response->headers->GetStatusLine(); |
| 2261 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2262 | // Delete the transaction without reading the response bodies. Then spin |
| 2263 | // the message loop, so the response bodies are drained. |
| 2264 | trans.reset(); |
| 2265 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2266 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2267 | |
| 2268 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2269 | "HTTP/1.1 204 No Content", |
| 2270 | "HTTP/1.1 205 Reset Content", |
| 2271 | "HTTP/1.1 304 Not Modified", |
| 2272 | "HTTP/1.1 302 Found", |
| 2273 | "HTTP/1.1 302 Found", |
| 2274 | "HTTP/1.1 301 Moved Permanently", |
| 2275 | "HTTP/1.1 301 Moved Permanently", |
| 2276 | "HTTP/1.1 200 Hunky-Dory", |
| 2277 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2278 | }; |
| 2279 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2280 | static_assert(kNumUnreadBodies == base::size(kStatusLines), |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2281 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2282 | |
| 2283 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2284 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2285 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2286 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2287 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2288 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2289 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2290 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2291 | ASSERT_TRUE(response); |
| 2292 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2293 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2294 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2295 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2296 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2297 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2298 | } |
| 2299 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2300 | // Sockets that receive extra data after a response is complete should not be |
| 2301 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2302 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2303 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2304 | MockWrite data_writes1[] = { |
| 2305 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2306 | "Host: www.borked.com\r\n" |
| 2307 | "Connection: keep-alive\r\n\r\n"), |
| 2308 | }; |
| 2309 | |
| 2310 | MockRead data_reads1[] = { |
| 2311 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2312 | "Connection: keep-alive\r\n" |
| 2313 | "Content-Length: 22\r\n\r\n" |
| 2314 | "This server is borked."), |
| 2315 | }; |
| 2316 | |
| 2317 | MockWrite data_writes2[] = { |
| 2318 | MockWrite("GET /foo 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_reads2[] = { |
| 2324 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2325 | "Content-Length: 3\r\n\r\n" |
| 2326 | "foo"), |
| 2327 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2328 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2329 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2330 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2331 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2332 | |
| 2333 | TestCompletionCallback callback; |
| 2334 | HttpRequestInfo request1; |
| 2335 | request1.method = "HEAD"; |
| 2336 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2337 | request1.traffic_annotation = |
| 2338 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2339 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2340 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2341 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2342 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2343 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2344 | |
| 2345 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2346 | ASSERT_TRUE(response1); |
| 2347 | ASSERT_TRUE(response1->headers); |
| 2348 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2349 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2350 | |
| 2351 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2352 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2353 | EXPECT_EQ("", response_data1); |
| 2354 | // Deleting the transaction attempts to release the socket back into the |
| 2355 | // socket pool. |
| 2356 | trans1.reset(); |
| 2357 | |
| 2358 | HttpRequestInfo request2; |
| 2359 | request2.method = "GET"; |
| 2360 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2361 | request2.traffic_annotation = |
| 2362 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2363 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2364 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2365 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2366 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2367 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2368 | |
| 2369 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2370 | ASSERT_TRUE(response2); |
| 2371 | ASSERT_TRUE(response2->headers); |
| 2372 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2373 | |
| 2374 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2375 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2376 | EXPECT_EQ("foo", response_data2); |
| 2377 | } |
| 2378 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2379 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2380 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2381 | MockWrite data_writes1[] = { |
| 2382 | MockWrite("GET / HTTP/1.1\r\n" |
| 2383 | "Host: www.borked.com\r\n" |
| 2384 | "Connection: keep-alive\r\n\r\n"), |
| 2385 | }; |
| 2386 | |
| 2387 | MockRead data_reads1[] = { |
| 2388 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2389 | "Connection: keep-alive\r\n" |
| 2390 | "Content-Length: 22\r\n\r\n" |
| 2391 | "This server is borked." |
| 2392 | "Bonus data!"), |
| 2393 | }; |
| 2394 | |
| 2395 | MockWrite data_writes2[] = { |
| 2396 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2397 | "Host: www.borked.com\r\n" |
| 2398 | "Connection: keep-alive\r\n\r\n"), |
| 2399 | }; |
| 2400 | |
| 2401 | MockRead data_reads2[] = { |
| 2402 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2403 | "Content-Length: 3\r\n\r\n" |
| 2404 | "foo"), |
| 2405 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2406 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2407 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2408 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2409 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2410 | |
| 2411 | TestCompletionCallback callback; |
| 2412 | HttpRequestInfo request1; |
| 2413 | request1.method = "GET"; |
| 2414 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2415 | request1.traffic_annotation = |
| 2416 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2417 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2418 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2419 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2420 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2421 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2422 | |
| 2423 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2424 | ASSERT_TRUE(response1); |
| 2425 | ASSERT_TRUE(response1->headers); |
| 2426 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2427 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2428 | |
| 2429 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2430 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2431 | EXPECT_EQ("This server is borked.", response_data1); |
| 2432 | // Deleting the transaction attempts to release the socket back into the |
| 2433 | // socket pool. |
| 2434 | trans1.reset(); |
| 2435 | |
| 2436 | HttpRequestInfo request2; |
| 2437 | request2.method = "GET"; |
| 2438 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2439 | request2.traffic_annotation = |
| 2440 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2441 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2442 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2443 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2444 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2445 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2446 | |
| 2447 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2448 | ASSERT_TRUE(response2); |
| 2449 | ASSERT_TRUE(response2->headers); |
| 2450 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2451 | |
| 2452 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2453 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2454 | EXPECT_EQ("foo", response_data2); |
| 2455 | } |
| 2456 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2457 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2458 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2459 | MockWrite data_writes1[] = { |
| 2460 | MockWrite("GET / HTTP/1.1\r\n" |
| 2461 | "Host: www.borked.com\r\n" |
| 2462 | "Connection: keep-alive\r\n\r\n"), |
| 2463 | }; |
| 2464 | |
| 2465 | MockRead data_reads1[] = { |
| 2466 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2467 | "Connection: keep-alive\r\n" |
| 2468 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2469 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2470 | MockRead("0\r\n\r\nBonus data!"), |
| 2471 | }; |
| 2472 | |
| 2473 | MockWrite data_writes2[] = { |
| 2474 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2475 | "Host: www.borked.com\r\n" |
| 2476 | "Connection: keep-alive\r\n\r\n"), |
| 2477 | }; |
| 2478 | |
| 2479 | MockRead data_reads2[] = { |
| 2480 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2481 | "Content-Length: 3\r\n\r\n" |
| 2482 | "foo"), |
| 2483 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2484 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2485 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2486 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2487 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2488 | |
| 2489 | TestCompletionCallback callback; |
| 2490 | HttpRequestInfo request1; |
| 2491 | request1.method = "GET"; |
| 2492 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2493 | request1.traffic_annotation = |
| 2494 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2495 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2496 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2497 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2498 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2499 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2500 | |
| 2501 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2502 | ASSERT_TRUE(response1); |
| 2503 | ASSERT_TRUE(response1->headers); |
| 2504 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2505 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2506 | |
| 2507 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2508 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2509 | EXPECT_EQ("This server is borked.", response_data1); |
| 2510 | // Deleting the transaction attempts to release the socket back into the |
| 2511 | // socket pool. |
| 2512 | trans1.reset(); |
| 2513 | |
| 2514 | HttpRequestInfo request2; |
| 2515 | request2.method = "GET"; |
| 2516 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2517 | request2.traffic_annotation = |
| 2518 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2519 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2520 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2521 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2522 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2523 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2524 | |
| 2525 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2526 | ASSERT_TRUE(response2); |
| 2527 | ASSERT_TRUE(response2->headers); |
| 2528 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2529 | |
| 2530 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2531 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2532 | EXPECT_EQ("foo", response_data2); |
| 2533 | } |
| 2534 | |
| 2535 | // This is a little different from the others - it tests the case that the |
| 2536 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2537 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2538 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2539 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2540 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2541 | MockWrite data_writes1[] = { |
| 2542 | MockWrite("GET / HTTP/1.1\r\n" |
| 2543 | "Host: www.borked.com\r\n" |
| 2544 | "Connection: keep-alive\r\n\r\n"), |
| 2545 | }; |
| 2546 | |
| 2547 | MockRead data_reads1[] = { |
| 2548 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2549 | "Connection: keep-alive\r\n" |
| 2550 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2551 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2552 | MockRead("0\r\n\r\nBonus data!"), |
| 2553 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2554 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2555 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2556 | |
| 2557 | TestCompletionCallback callback; |
| 2558 | HttpRequestInfo request1; |
| 2559 | request1.method = "GET"; |
| 2560 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2561 | request1.traffic_annotation = |
| 2562 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2563 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2564 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2565 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2566 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2567 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2568 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2569 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2570 | ASSERT_TRUE(response1); |
| 2571 | ASSERT_TRUE(response1->headers); |
| 2572 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2573 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2574 | |
| 2575 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2576 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2577 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2578 | |
| 2579 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2580 | // socket can't be reused, rather than returning it to the socket pool. |
| 2581 | base::RunLoop().RunUntilIdle(); |
| 2582 | |
| 2583 | // There should be no idle sockets in the pool. |
| 2584 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2585 | } |
| 2586 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2587 | // Test the request-challenge-retry sequence for basic auth. |
| 2588 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2589 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2590 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2591 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2592 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2593 | request.traffic_annotation = |
| 2594 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2595 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2596 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2597 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2598 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2599 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2600 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2601 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2602 | MockWrite( |
| 2603 | "GET / HTTP/1.1\r\n" |
| 2604 | "Host: www.example.org\r\n" |
| 2605 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2606 | }; |
| 2607 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2608 | MockRead data_reads1[] = { |
| 2609 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2610 | // Give a couple authenticate options (only the middle one is actually |
| 2611 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2612 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2613 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2614 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2615 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2616 | // Large content-length -- won't matter, as connection will be reset. |
| 2617 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2618 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2619 | }; |
| 2620 | |
| 2621 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2622 | // be issuing -- the final header line contains the credentials. |
| 2623 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2624 | MockWrite( |
| 2625 | "GET / HTTP/1.1\r\n" |
| 2626 | "Host: www.example.org\r\n" |
| 2627 | "Connection: keep-alive\r\n" |
| 2628 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2629 | }; |
| 2630 | |
| 2631 | // Lastly, the server responds with the actual content. |
| 2632 | MockRead data_reads2[] = { |
| 2633 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2634 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2635 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2636 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2637 | }; |
| 2638 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2639 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2640 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2641 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2642 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2643 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2644 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2645 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2646 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2647 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2648 | |
| 2649 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2650 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2651 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2652 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2653 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2654 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2655 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2656 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2657 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2658 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2659 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2660 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2661 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2662 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2663 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2664 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2665 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2666 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2667 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2668 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2669 | |
| 2670 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2671 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2672 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2673 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2674 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2675 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2676 | // The load timing after restart should have a new socket ID, and times after |
| 2677 | // those of the first load timing. |
| 2678 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2679 | load_timing_info2.connect_timing.connect_start); |
| 2680 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2681 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2682 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2683 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2684 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2685 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2686 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2687 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2688 | ASSERT_TRUE(response); |
| 2689 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2690 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2691 | } |
| 2692 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2693 | // Test the request-challenge-retry sequence for basic auth. |
| 2694 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2695 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2696 | HttpRequestInfo request; |
| 2697 | request.method = "GET"; |
| 2698 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2699 | request.traffic_annotation = |
| 2700 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2701 | |
| 2702 | TestNetLog log; |
| 2703 | MockHostResolver* resolver = new MockHostResolver(); |
| 2704 | session_deps_.net_log = &log; |
| 2705 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2706 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2707 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2708 | |
| 2709 | resolver->rules()->ClearRules(); |
| 2710 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2711 | |
| 2712 | MockWrite data_writes1[] = { |
| 2713 | MockWrite("GET / HTTP/1.1\r\n" |
| 2714 | "Host: www.example.org\r\n" |
| 2715 | "Connection: keep-alive\r\n\r\n"), |
| 2716 | }; |
| 2717 | |
| 2718 | MockRead data_reads1[] = { |
| 2719 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2720 | // Give a couple authenticate options (only the middle one is actually |
| 2721 | // supported). |
| 2722 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2723 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2724 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2725 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2726 | // Large content-length -- won't matter, as connection will be reset. |
| 2727 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2728 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2729 | }; |
| 2730 | |
| 2731 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2732 | // be issuing -- the final header line contains the credentials. |
| 2733 | MockWrite data_writes2[] = { |
| 2734 | MockWrite("GET / HTTP/1.1\r\n" |
| 2735 | "Host: www.example.org\r\n" |
| 2736 | "Connection: keep-alive\r\n" |
| 2737 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2738 | }; |
| 2739 | |
| 2740 | // Lastly, the server responds with the actual content. |
| 2741 | MockRead data_reads2[] = { |
| 2742 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2743 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2744 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2745 | }; |
| 2746 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2747 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2748 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2749 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2750 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2751 | |
| 2752 | TestCompletionCallback callback1; |
| 2753 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2754 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2755 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2756 | |
| 2757 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2758 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2759 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2760 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2761 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2762 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2763 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2764 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2765 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2766 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2767 | ASSERT_TRUE(response); |
| 2768 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2769 | |
| 2770 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2771 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2772 | ASSERT_FALSE(endpoint.address().empty()); |
| 2773 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2774 | |
| 2775 | resolver->rules()->ClearRules(); |
| 2776 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2777 | |
| 2778 | TestCompletionCallback callback2; |
| 2779 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2780 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2781 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2782 | |
| 2783 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2784 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2785 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2786 | // The load timing after restart should have a new socket ID, and times after |
| 2787 | // those of the first load timing. |
| 2788 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2789 | load_timing_info2.connect_timing.connect_start); |
| 2790 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2791 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2792 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2793 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2794 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2795 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2796 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2797 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2798 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2799 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2800 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2801 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2802 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2803 | ASSERT_FALSE(endpoint.address().empty()); |
| 2804 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2805 | } |
| 2806 | |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2807 | // Test that, if the server requests auth indefinitely, HttpNetworkTransaction |
| 2808 | // will eventually give up. |
| 2809 | TEST_F(HttpNetworkTransactionTest, BasicAuthForever) { |
| 2810 | HttpRequestInfo request; |
| 2811 | request.method = "GET"; |
| 2812 | request.url = GURL("http://www.example.org/"); |
| 2813 | request.traffic_annotation = |
| 2814 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2815 | |
| 2816 | TestNetLog log; |
| 2817 | session_deps_.net_log = &log; |
| 2818 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2819 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 2820 | |
| 2821 | MockWrite data_writes[] = { |
| 2822 | MockWrite("GET / HTTP/1.1\r\n" |
| 2823 | "Host: www.example.org\r\n" |
| 2824 | "Connection: keep-alive\r\n\r\n"), |
| 2825 | }; |
| 2826 | |
| 2827 | MockRead data_reads[] = { |
| 2828 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2829 | // Give a couple authenticate options (only the middle one is actually |
| 2830 | // supported). |
| 2831 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2832 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2833 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2834 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2835 | // Large content-length -- won't matter, as connection will be reset. |
| 2836 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2837 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2838 | }; |
| 2839 | |
| 2840 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2841 | // be issuing -- the final header line contains the credentials. |
| 2842 | MockWrite data_writes_restart[] = { |
| 2843 | MockWrite("GET / HTTP/1.1\r\n" |
| 2844 | "Host: www.example.org\r\n" |
| 2845 | "Connection: keep-alive\r\n" |
| 2846 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2847 | }; |
| 2848 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2849 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2850 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2851 | |
| 2852 | TestCompletionCallback callback; |
| 2853 | int rv = callback.GetResult( |
| 2854 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 2855 | |
| 2856 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_restarts; |
| 2857 | for (int i = 0; i < 32; i++) { |
| 2858 | // Check the previous response was a 401. |
| 2859 | EXPECT_THAT(rv, IsOk()); |
| 2860 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 2861 | ASSERT_TRUE(response); |
| 2862 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2863 | |
| 2864 | data_restarts.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2865 | data_reads, data_writes_restart)); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2866 | session_deps_.socket_factory->AddSocketDataProvider( |
| 2867 | data_restarts.back().get()); |
| 2868 | rv = callback.GetResult(trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2869 | callback.callback())); |
| 2870 | } |
| 2871 | |
| 2872 | // After too many tries, the transaction should have given up. |
| 2873 | EXPECT_THAT(rv, IsError(ERR_TOO_MANY_RETRIES)); |
| 2874 | } |
| 2875 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2876 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2877 | HttpRequestInfo request; |
| 2878 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2879 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2880 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2881 | request.traffic_annotation = |
| 2882 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2883 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2884 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2885 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2886 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2887 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2888 | MockWrite( |
| 2889 | "GET / HTTP/1.1\r\n" |
| 2890 | "Host: www.example.org\r\n" |
| 2891 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2892 | }; |
| 2893 | |
| 2894 | MockRead data_reads[] = { |
| 2895 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2896 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2897 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2898 | // Large content-length -- won't matter, as connection will be reset. |
| 2899 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2900 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2901 | }; |
| 2902 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2903 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2904 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2905 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2906 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2907 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2908 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2909 | |
| 2910 | rv = callback.WaitForResult(); |
| 2911 | EXPECT_EQ(0, rv); |
| 2912 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2913 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2914 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2915 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2916 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2917 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2918 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2919 | ASSERT_TRUE(response); |
| 2920 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2921 | } |
| 2922 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2923 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2924 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2925 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2926 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2927 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2928 | // reused. See http://crbug.com/544255. |
| 2929 | for (int i = 0; i < 2; ++i) { |
| 2930 | HttpRequestInfo request; |
| 2931 | request.method = "GET"; |
| 2932 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2933 | request.traffic_annotation = |
| 2934 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2935 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2936 | TestNetLog log; |
| 2937 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2938 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2939 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2940 | MockWrite data_writes[] = { |
| 2941 | MockWrite(ASYNC, 0, |
| 2942 | "GET / HTTP/1.1\r\n" |
| 2943 | "Host: www.example.org\r\n" |
| 2944 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2945 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2946 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2947 | // be issuing -- the final header line contains the credentials. |
| 2948 | MockWrite(ASYNC, 6, |
| 2949 | "GET / HTTP/1.1\r\n" |
| 2950 | "Host: www.example.org\r\n" |
| 2951 | "Connection: keep-alive\r\n" |
| 2952 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2953 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2954 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2955 | MockRead data_reads[] = { |
| 2956 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2957 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2958 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2959 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2960 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2961 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2962 | // Lastly, the server responds with the actual content. |
| 2963 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2964 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2965 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2966 | MockRead(ASYNC, 10, "Hello"), |
| 2967 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2968 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2969 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2970 | data.set_busy_before_sync_reads(true); |
| 2971 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2972 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2973 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2974 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2975 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2976 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2977 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2978 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2979 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2980 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2981 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2982 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2983 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2984 | ASSERT_TRUE(response); |
| 2985 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2986 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2987 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2988 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2989 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2990 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2991 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2992 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2993 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2994 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2995 | TestLoadTimingReused(load_timing_info2); |
| 2996 | // The load timing after restart should have the same socket ID, and times |
| 2997 | // those of the first load timing. |
| 2998 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2999 | load_timing_info2.send_start); |
| 3000 | 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] | 3001 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3002 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3003 | ASSERT_TRUE(response); |
| 3004 | EXPECT_FALSE(response->auth_challenge); |
| 3005 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3006 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3007 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3008 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3009 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3010 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3011 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3012 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3013 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3014 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3015 | } |
| 3016 | |
| 3017 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3018 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3019 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3020 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3021 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3022 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3023 | request.traffic_annotation = |
| 3024 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3025 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3026 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3027 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3028 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3029 | MockWrite("GET / HTTP/1.1\r\n" |
| 3030 | "Host: www.example.org\r\n" |
| 3031 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3032 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3033 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3034 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3035 | MockWrite("GET / HTTP/1.1\r\n" |
| 3036 | "Host: www.example.org\r\n" |
| 3037 | "Connection: keep-alive\r\n" |
| 3038 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3039 | }; |
| 3040 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3041 | MockRead data_reads1[] = { |
| 3042 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3043 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3044 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3045 | |
| 3046 | // Lastly, the server responds with the actual content. |
| 3047 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3048 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3049 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3050 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3051 | }; |
| 3052 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3053 | // An incorrect reconnect would cause this to be read. |
| 3054 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3055 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3056 | }; |
| 3057 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3058 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3059 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3060 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3061 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3062 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3063 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3064 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3065 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3066 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3067 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3068 | |
| 3069 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3070 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3071 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3072 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3073 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3074 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[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 callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3077 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3078 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3079 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3080 | |
| 3081 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3082 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3083 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3084 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3085 | ASSERT_TRUE(response); |
| 3086 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3087 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3088 | } |
| 3089 | |
| 3090 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3091 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3092 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3093 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3094 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3095 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3096 | request.traffic_annotation = |
| 3097 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3098 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3099 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3100 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3101 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3102 | MockWrite("GET / HTTP/1.1\r\n" |
| 3103 | "Host: www.example.org\r\n" |
| 3104 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3105 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3106 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3107 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3108 | MockWrite("GET / HTTP/1.1\r\n" |
| 3109 | "Host: www.example.org\r\n" |
| 3110 | "Connection: keep-alive\r\n" |
| 3111 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3112 | }; |
| 3113 | |
| 3114 | // Respond with 5 kb of response body. |
| 3115 | std::string large_body_string("Unauthorized"); |
| 3116 | large_body_string.append(5 * 1024, ' '); |
| 3117 | large_body_string.append("\r\n"); |
| 3118 | |
| 3119 | MockRead data_reads1[] = { |
| 3120 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3121 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3122 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3123 | // 5134 = 12 + 5 * 1024 + 2 |
| 3124 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3125 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3126 | |
| 3127 | // Lastly, the server responds with the actual content. |
| 3128 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3129 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3130 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3131 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3132 | }; |
| 3133 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3134 | // An incorrect reconnect would cause this to be read. |
| 3135 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3136 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3137 | }; |
| 3138 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3139 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3140 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3141 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3142 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3143 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3144 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3145 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3146 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3147 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3148 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3149 | |
| 3150 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3151 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3152 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3153 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3154 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3155 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[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 callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3158 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3159 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3160 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3161 | |
| 3162 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3163 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3164 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3165 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3166 | ASSERT_TRUE(response); |
| 3167 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3168 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3169 | } |
| 3170 | |
| 3171 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3172 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3173 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3174 | HttpRequestInfo request; |
| 3175 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3176 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3177 | request.traffic_annotation = |
| 3178 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3179 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3180 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3181 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3182 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3183 | MockWrite( |
| 3184 | "GET / HTTP/1.1\r\n" |
| 3185 | "Host: www.example.org\r\n" |
| 3186 | "Connection: keep-alive\r\n\r\n"), |
| 3187 | // This simulates the seemingly successful write to a closed connection |
| 3188 | // if the bug is not fixed. |
| 3189 | MockWrite( |
| 3190 | "GET / HTTP/1.1\r\n" |
| 3191 | "Host: www.example.org\r\n" |
| 3192 | "Connection: keep-alive\r\n" |
| 3193 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3194 | }; |
| 3195 | |
| 3196 | MockRead data_reads1[] = { |
| 3197 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3198 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3199 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3200 | MockRead("Content-Length: 14\r\n\r\n"), |
| 3201 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3202 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3203 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3204 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3205 | }; |
| 3206 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3207 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3208 | // be issuing -- the final header line contains the credentials. |
| 3209 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3210 | MockWrite( |
| 3211 | "GET / HTTP/1.1\r\n" |
| 3212 | "Host: www.example.org\r\n" |
| 3213 | "Connection: keep-alive\r\n" |
| 3214 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3215 | }; |
| 3216 | |
| 3217 | // Lastly, the server responds with the actual content. |
| 3218 | MockRead data_reads2[] = { |
| 3219 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3220 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3221 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3222 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3223 | }; |
| 3224 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3225 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3226 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3227 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3228 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3229 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3230 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3231 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3232 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3233 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3234 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3235 | |
| 3236 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3237 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3238 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3239 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3240 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3241 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[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 callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3244 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3245 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3246 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3247 | |
| 3248 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3249 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3250 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3251 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3252 | ASSERT_TRUE(response); |
| 3253 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3254 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3255 | } |
| 3256 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3257 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3258 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3259 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3260 | HttpRequestInfo request; |
| 3261 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3262 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3263 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3264 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3265 | request.traffic_annotation = |
| 3266 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3267 | |
| 3268 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3269 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3270 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3271 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3272 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3273 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3274 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3275 | |
| 3276 | // Since we have proxy, should try to establish tunnel. |
| 3277 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3278 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3279 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3280 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3281 | }; |
| 3282 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3283 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3284 | // connection. |
| 3285 | MockRead data_reads1[] = { |
| 3286 | // No credentials. |
| 3287 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3288 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3289 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3290 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3291 | // Since the first connection couldn't be reused, need to establish another |
| 3292 | // once given credentials. |
| 3293 | MockWrite data_writes2[] = { |
| 3294 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3295 | // be issuing -- the final header line contains the credentials. |
| 3296 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3297 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3298 | "Proxy-Connection: keep-alive\r\n" |
| 3299 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3300 | |
| 3301 | MockWrite("GET / HTTP/1.1\r\n" |
| 3302 | "Host: www.example.org\r\n" |
| 3303 | "Connection: keep-alive\r\n\r\n"), |
| 3304 | }; |
| 3305 | |
| 3306 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3307 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3308 | |
| 3309 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3310 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3311 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3312 | MockRead(SYNCHRONOUS, "hello"), |
| 3313 | }; |
| 3314 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3315 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3316 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3317 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3318 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3319 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3320 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3321 | |
| 3322 | TestCompletionCallback callback1; |
| 3323 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3324 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3325 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3326 | |
| 3327 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3328 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3329 | |
| 3330 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3331 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3332 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3333 | log.GetEntries(&entries); |
| 3334 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3335 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3336 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3337 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3338 | entries, pos, |
| 3339 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3340 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3341 | |
| 3342 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3343 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3344 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3345 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3346 | EXPECT_EQ(407, response->headers->response_code()); |
| 3347 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3348 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3349 | |
| 3350 | LoadTimingInfo load_timing_info; |
| 3351 | // CONNECT requests and responses are handled at the connect job level, so |
| 3352 | // the transaction does not yet have a connection. |
| 3353 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3354 | |
| 3355 | TestCompletionCallback callback2; |
| 3356 | |
| 3357 | rv = |
| 3358 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3359 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3360 | |
| 3361 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3362 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3363 | |
| 3364 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3365 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3366 | |
| 3367 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3368 | EXPECT_EQ(200, response->headers->response_code()); |
| 3369 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3370 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3371 | |
| 3372 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3373 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3374 | |
| 3375 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3376 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3377 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3378 | |
| 3379 | trans.reset(); |
| 3380 | session->CloseAllConnections(); |
| 3381 | } |
| 3382 | |
| 3383 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3384 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3385 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3386 | HttpRequestInfo request; |
| 3387 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3388 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3389 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3390 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3391 | request.traffic_annotation = |
| 3392 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3393 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3394 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3395 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3396 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3397 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3398 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3399 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3400 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3401 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3402 | // Since we have proxy, should try to establish tunnel. |
| 3403 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3404 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3405 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3406 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3407 | }; |
| 3408 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3409 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3410 | // connection. |
| 3411 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3412 | // No credentials. |
| 3413 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3414 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3415 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3416 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3417 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3418 | MockWrite data_writes2[] = { |
| 3419 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3420 | // be issuing -- the final header line contains the credentials. |
| 3421 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3422 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3423 | "Proxy-Connection: keep-alive\r\n" |
| 3424 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3425 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3426 | MockWrite("GET / HTTP/1.1\r\n" |
| 3427 | "Host: www.example.org\r\n" |
| 3428 | "Connection: keep-alive\r\n\r\n"), |
| 3429 | }; |
| 3430 | |
| 3431 | MockRead data_reads2[] = { |
| 3432 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3433 | |
| 3434 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3435 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3436 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3437 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3438 | }; |
| 3439 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3440 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3441 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3442 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3443 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3444 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3445 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3446 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3447 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3448 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3449 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3450 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3451 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3452 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3453 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3454 | |
| 3455 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3456 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3457 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3458 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3459 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3460 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3461 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3462 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3463 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3464 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3465 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3466 | |
| 3467 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3468 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3469 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3470 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3471 | EXPECT_EQ(407, response->headers->response_code()); |
| 3472 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3473 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3474 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3475 | LoadTimingInfo load_timing_info; |
| 3476 | // CONNECT requests and responses are handled at the connect job level, so |
| 3477 | // the transaction does not yet have a connection. |
| 3478 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3479 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3480 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3481 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3482 | rv = trans->RestartWithAuth( |
| 3483 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3484 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3485 | |
| 3486 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3487 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3488 | |
| 3489 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3490 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3491 | |
| 3492 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3493 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3494 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3495 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3496 | |
| 3497 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3498 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3499 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3500 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3501 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3502 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3503 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3504 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3505 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3506 | } |
| 3507 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3508 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3509 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3510 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3511 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3512 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3513 | // reused. See http://crbug.com/544255. |
| 3514 | for (int i = 0; i < 2; ++i) { |
| 3515 | HttpRequestInfo request; |
| 3516 | request.method = "GET"; |
| 3517 | request.url = GURL("https://www.example.org/"); |
| 3518 | // Ensure that proxy authentication is attempted even |
| 3519 | // when the no authentication data flag is set. |
| 3520 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3521 | request.traffic_annotation = |
| 3522 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3523 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3524 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3525 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3526 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3527 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3528 | BoundTestNetLog log; |
| 3529 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3530 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3531 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3532 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3533 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3534 | // Since we have proxy, should try to establish tunnel. |
| 3535 | MockWrite data_writes1[] = { |
| 3536 | MockWrite(ASYNC, 0, |
| 3537 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3538 | "Host: www.example.org:443\r\n" |
| 3539 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3540 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3541 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3542 | // be issuing -- the final header line contains the credentials. |
| 3543 | MockWrite(ASYNC, 3, |
| 3544 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3545 | "Host: www.example.org:443\r\n" |
| 3546 | "Proxy-Connection: keep-alive\r\n" |
| 3547 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3548 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3549 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3550 | // The proxy responds to the connect with a 407, using a persistent |
| 3551 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3552 | MockRead data_reads1[] = { |
| 3553 | // No credentials. |
| 3554 | MockRead(ASYNC, 1, |
| 3555 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3556 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3557 | "Proxy-Connection: keep-alive\r\n" |
| 3558 | "Content-Length: 10\r\n\r\n"), |
| 3559 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3560 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3561 | // Wrong credentials (wrong password). |
| 3562 | MockRead(ASYNC, 4, |
| 3563 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3564 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3565 | "Proxy-Connection: keep-alive\r\n" |
| 3566 | "Content-Length: 10\r\n\r\n"), |
| 3567 | // No response body because the test stops reading here. |
| 3568 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3569 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3570 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3571 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3572 | data1.set_busy_before_sync_reads(true); |
| 3573 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3574 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3575 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3576 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3577 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3578 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3579 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3580 | TestNetLogEntry::List entries; |
| 3581 | log.GetEntries(&entries); |
| 3582 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3583 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3584 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3585 | ExpectLogContainsSomewhere( |
| 3586 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3587 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3588 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3589 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3590 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3591 | ASSERT_TRUE(response); |
| 3592 | ASSERT_TRUE(response->headers); |
| 3593 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3594 | EXPECT_EQ(407, response->headers->response_code()); |
| 3595 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3596 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3597 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3598 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3599 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3600 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3601 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3602 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3603 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3604 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3605 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3606 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3607 | ASSERT_TRUE(response); |
| 3608 | ASSERT_TRUE(response->headers); |
| 3609 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3610 | EXPECT_EQ(407, response->headers->response_code()); |
| 3611 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3612 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3613 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3614 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3615 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3616 | // out of scope. |
| 3617 | session->CloseAllConnections(); |
| 3618 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3619 | } |
| 3620 | |
| 3621 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3622 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3623 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3624 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3625 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3626 | // reused. See http://crbug.com/544255. |
| 3627 | for (int i = 0; i < 2; ++i) { |
| 3628 | HttpRequestInfo request; |
| 3629 | request.method = "GET"; |
| 3630 | request.url = GURL("https://www.example.org/"); |
| 3631 | // Ensure that proxy authentication is attempted even |
| 3632 | // when the no authentication data flag is set. |
| 3633 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3634 | request.traffic_annotation = |
| 3635 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3636 | |
| 3637 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3638 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3639 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3640 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3641 | BoundTestNetLog log; |
| 3642 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3643 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3644 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3645 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3646 | |
| 3647 | // Since we have proxy, should try to establish tunnel. |
| 3648 | MockWrite data_writes1[] = { |
| 3649 | MockWrite(ASYNC, 0, |
| 3650 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3651 | "Host: www.example.org:443\r\n" |
| 3652 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3653 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3654 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3655 | // be issuing -- the final header line contains the credentials. |
| 3656 | MockWrite(ASYNC, 3, |
| 3657 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3658 | "Host: www.example.org:443\r\n" |
| 3659 | "Proxy-Connection: keep-alive\r\n" |
| 3660 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3661 | }; |
| 3662 | |
| 3663 | // The proxy responds to the connect with a 407, using a persistent |
| 3664 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3665 | MockRead data_reads1[] = { |
| 3666 | // No credentials. |
| 3667 | MockRead(ASYNC, 1, |
| 3668 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3669 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3670 | "Content-Length: 10\r\n\r\n"), |
| 3671 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3672 | |
| 3673 | // Wrong credentials (wrong password). |
| 3674 | MockRead(ASYNC, 4, |
| 3675 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3676 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3677 | "Content-Length: 10\r\n\r\n"), |
| 3678 | // No response body because the test stops reading here. |
| 3679 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3680 | }; |
| 3681 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3682 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3683 | data1.set_busy_before_sync_reads(true); |
| 3684 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3685 | |
| 3686 | TestCompletionCallback callback1; |
| 3687 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3688 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3689 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3690 | |
| 3691 | TestNetLogEntry::List entries; |
| 3692 | log.GetEntries(&entries); |
| 3693 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3694 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3695 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3696 | ExpectLogContainsSomewhere( |
| 3697 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3698 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3699 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3700 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3701 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3702 | ASSERT_TRUE(response); |
| 3703 | ASSERT_TRUE(response->headers); |
| 3704 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3705 | EXPECT_EQ(407, response->headers->response_code()); |
| 3706 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3707 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3708 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3709 | |
| 3710 | TestCompletionCallback callback2; |
| 3711 | |
| 3712 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3713 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3714 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3715 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3716 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3717 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3718 | ASSERT_TRUE(response); |
| 3719 | ASSERT_TRUE(response->headers); |
| 3720 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3721 | EXPECT_EQ(407, response->headers->response_code()); |
| 3722 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3723 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3724 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3725 | |
| 3726 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3727 | // out of scope. |
| 3728 | session->CloseAllConnections(); |
| 3729 | } |
| 3730 | } |
| 3731 | |
| 3732 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3733 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3734 | // the case the server sends extra data on the original socket, so it can't be |
| 3735 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3736 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3737 | HttpRequestInfo request; |
| 3738 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3739 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3740 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3741 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3742 | request.traffic_annotation = |
| 3743 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3744 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3745 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3746 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3747 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3748 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3749 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3750 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3751 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3752 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3753 | // Since we have proxy, should try to establish tunnel. |
| 3754 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3755 | MockWrite(ASYNC, 0, |
| 3756 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3757 | "Host: www.example.org:443\r\n" |
| 3758 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3759 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3760 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3761 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3762 | // extra data, so the socket cannot be reused. |
| 3763 | MockRead data_reads1[] = { |
| 3764 | // No credentials. |
| 3765 | MockRead(ASYNC, 1, |
| 3766 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3767 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3768 | "Content-Length: 10\r\n\r\n"), |
| 3769 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3770 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3771 | }; |
| 3772 | |
| 3773 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3774 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3775 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3776 | MockWrite(ASYNC, 0, |
| 3777 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3778 | "Host: www.example.org:443\r\n" |
| 3779 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3780 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3781 | |
| 3782 | MockWrite(ASYNC, 2, |
| 3783 | "GET / HTTP/1.1\r\n" |
| 3784 | "Host: www.example.org\r\n" |
| 3785 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3786 | }; |
| 3787 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3788 | MockRead data_reads2[] = { |
| 3789 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3790 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3791 | MockRead(ASYNC, 3, |
| 3792 | "HTTP/1.1 200 OK\r\n" |
| 3793 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3794 | "Content-Length: 5\r\n\r\n"), |
| 3795 | // No response body because the test stops reading here. |
| 3796 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3797 | }; |
| 3798 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3799 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3800 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3801 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3802 | SequencedSocketData data2(data_reads2, data_writes2); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3803 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3804 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3805 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3806 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3807 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3808 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3809 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3810 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3811 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3812 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3813 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3814 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3815 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3816 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3817 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3818 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3819 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3820 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3821 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3822 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3823 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3824 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3825 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3826 | ASSERT_TRUE(response); |
| 3827 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3828 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3829 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3830 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3831 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3832 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3833 | LoadTimingInfo load_timing_info; |
| 3834 | // CONNECT requests and responses are handled at the connect job level, so |
| 3835 | // the transaction does not yet have a connection. |
| 3836 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3837 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3838 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3839 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3840 | rv = |
| 3841 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3842 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3843 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3844 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3845 | EXPECT_EQ(200, response->headers->response_code()); |
| 3846 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3847 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3848 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3849 | // The password prompt info should not be set. |
| 3850 | EXPECT_FALSE(response->auth_challenge); |
| 3851 | |
| 3852 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3853 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3854 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3855 | |
| 3856 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3857 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3858 | } |
| 3859 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3860 | // Test the case a proxy closes a socket while the challenge body is being |
| 3861 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3862 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3863 | HttpRequestInfo request; |
| 3864 | request.method = "GET"; |
| 3865 | request.url = GURL("https://www.example.org/"); |
| 3866 | // Ensure that proxy authentication is attempted even |
| 3867 | // when the no authentication data flag is set. |
| 3868 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3869 | request.traffic_annotation = |
| 3870 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3871 | |
| 3872 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3873 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3874 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3875 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3876 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3877 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3878 | |
| 3879 | // Since we have proxy, should try to establish tunnel. |
| 3880 | MockWrite data_writes1[] = { |
| 3881 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3882 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3883 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3884 | }; |
| 3885 | |
| 3886 | // The proxy responds to the connect with a 407, using a persistent |
| 3887 | // connection. |
| 3888 | MockRead data_reads1[] = { |
| 3889 | // No credentials. |
| 3890 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3891 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3892 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3893 | // Server hands up in the middle of the body. |
| 3894 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3895 | }; |
| 3896 | |
| 3897 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3898 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3899 | // be issuing -- the final header line contains the credentials. |
| 3900 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3901 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3902 | "Proxy-Connection: keep-alive\r\n" |
| 3903 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3904 | |
| 3905 | MockWrite("GET / HTTP/1.1\r\n" |
| 3906 | "Host: www.example.org\r\n" |
| 3907 | "Connection: keep-alive\r\n\r\n"), |
| 3908 | }; |
| 3909 | |
| 3910 | MockRead data_reads2[] = { |
| 3911 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3912 | |
| 3913 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3914 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3915 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3916 | MockRead(SYNCHRONOUS, "hello"), |
| 3917 | }; |
| 3918 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3919 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3920 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3921 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3922 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3923 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3924 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3925 | |
| 3926 | TestCompletionCallback callback; |
| 3927 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3928 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3929 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3930 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3931 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3932 | ASSERT_TRUE(response); |
| 3933 | ASSERT_TRUE(response->headers); |
| 3934 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3935 | EXPECT_EQ(407, response->headers->response_code()); |
| 3936 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3937 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3938 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3939 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3940 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3941 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3942 | ASSERT_TRUE(response); |
| 3943 | ASSERT_TRUE(response->headers); |
| 3944 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3945 | EXPECT_EQ(200, response->headers->response_code()); |
| 3946 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3947 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3948 | EXPECT_EQ("hello", body); |
| 3949 | } |
| 3950 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3951 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3952 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3953 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3954 | HttpRequestInfo request; |
| 3955 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3956 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3957 | request.traffic_annotation = |
| 3958 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3959 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3960 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3961 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3962 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3963 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3964 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3965 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3966 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3967 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3968 | // Since we have proxy, should try to establish tunnel. |
| 3969 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3970 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3971 | "Host: www.example.org:443\r\n" |
| 3972 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3973 | }; |
| 3974 | |
| 3975 | // The proxy responds to the connect with a 407. |
| 3976 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3977 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3978 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3979 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3980 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3981 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3982 | }; |
| 3983 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3984 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3985 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3986 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3987 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3988 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3989 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3990 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3991 | |
| 3992 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3993 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3994 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3995 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3996 | ASSERT_TRUE(response); |
| 3997 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3998 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3999 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4000 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4001 | |
| 4002 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4003 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4004 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 4005 | |
| 4006 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 4007 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4008 | } |
| 4009 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4010 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 4011 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4012 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4013 | HttpRequestInfo request; |
| 4014 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4015 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4016 | request.traffic_annotation = |
| 4017 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4018 | |
| 4019 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4020 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4021 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4022 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4023 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4024 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4025 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4026 | |
| 4027 | // Since we have proxy, should try to establish tunnel. |
| 4028 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4029 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4030 | "Host: www.example.org:443\r\n" |
| 4031 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4032 | }; |
| 4033 | |
| 4034 | // The proxy responds to the connect with a 407. |
| 4035 | MockRead data_reads[] = { |
| 4036 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4037 | MockRead("X-Foo: bar\r\n"), |
| 4038 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 4039 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4040 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4041 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4042 | }; |
| 4043 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4044 | StaticSocketDataProvider data(data_reads, data_writes); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4045 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4046 | |
| 4047 | TestCompletionCallback callback; |
| 4048 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4049 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4050 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4051 | |
| 4052 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4053 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4054 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4055 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4056 | ASSERT_TRUE(response); |
| 4057 | ASSERT_TRUE(response->headers); |
| 4058 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4059 | EXPECT_EQ(407, response->headers->response_code()); |
| 4060 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4061 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 4062 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 4063 | |
| 4064 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4065 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4066 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4067 | |
| 4068 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 4069 | session->CloseAllConnections(); |
| 4070 | } |
| 4071 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4072 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 4073 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4074 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4075 | HttpRequestInfo request; |
| 4076 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4077 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4078 | request.traffic_annotation = |
| 4079 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4080 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4081 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4082 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4083 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4084 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4085 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4086 | MockWrite( |
| 4087 | "GET / HTTP/1.1\r\n" |
| 4088 | "Host: www.example.org\r\n" |
| 4089 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4090 | }; |
| 4091 | |
| 4092 | MockRead data_reads1[] = { |
| 4093 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 4094 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4095 | // Large content-length -- won't matter, as connection will be reset. |
| 4096 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4097 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4098 | }; |
| 4099 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4100 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4101 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4102 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4103 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4104 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4105 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4106 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4107 | |
| 4108 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4109 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4110 | } |
| 4111 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4112 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 4113 | // through a non-authenticating proxy. The request should fail with |
| 4114 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 4115 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 4116 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 4117 | // response came from the proxy or the server, so it is treated as if the proxy |
| 4118 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4119 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4120 | HttpRequestInfo request; |
| 4121 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4122 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4123 | request.traffic_annotation = |
| 4124 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4125 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4126 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4127 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4128 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4129 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4130 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4131 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4132 | // Since we have proxy, should try to establish tunnel. |
| 4133 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4134 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4135 | "Host: www.example.org:443\r\n" |
| 4136 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4137 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4138 | MockWrite("GET / HTTP/1.1\r\n" |
| 4139 | "Host: www.example.org\r\n" |
| 4140 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4141 | }; |
| 4142 | |
| 4143 | MockRead data_reads1[] = { |
| 4144 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4145 | |
| 4146 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 4147 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4148 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4149 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4150 | }; |
| 4151 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4152 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4153 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4154 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4155 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4156 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4157 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4158 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4159 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4160 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4161 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4162 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4163 | |
| 4164 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4165 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 4166 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4167 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4168 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4169 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 4170 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4171 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4172 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4173 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 4174 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4175 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4176 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4177 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4178 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4179 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4180 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 4181 | HttpRequestInfo request; |
| 4182 | request.method = "GET"; |
| 4183 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4184 | request.traffic_annotation = |
| 4185 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4186 | |
| 4187 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4188 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4189 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4190 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4191 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4192 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4193 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4194 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4195 | mock_handler->set_allows_default_credentials(true); |
| 4196 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4197 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4198 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4199 | |
| 4200 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4201 | NetLog net_log; |
| 4202 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4203 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4204 | |
| 4205 | // Since we have proxy, should try to establish tunnel. |
| 4206 | MockWrite data_writes1[] = { |
| 4207 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4208 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4209 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4210 | }; |
| 4211 | |
| 4212 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4213 | // connection. |
| 4214 | MockRead data_reads1[] = { |
| 4215 | // No credentials. |
| 4216 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4217 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4218 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4219 | }; |
| 4220 | |
| 4221 | // Since the first connection couldn't be reused, need to establish another |
| 4222 | // once given credentials. |
| 4223 | MockWrite data_writes2[] = { |
| 4224 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4225 | // be issuing -- the final header line contains the credentials. |
| 4226 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4227 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4228 | "Proxy-Connection: keep-alive\r\n" |
| 4229 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4230 | |
| 4231 | MockWrite("GET / HTTP/1.1\r\n" |
| 4232 | "Host: www.example.org\r\n" |
| 4233 | "Connection: keep-alive\r\n\r\n"), |
| 4234 | }; |
| 4235 | |
| 4236 | MockRead data_reads2[] = { |
| 4237 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4238 | |
| 4239 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4240 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4241 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4242 | MockRead(SYNCHRONOUS, "hello"), |
| 4243 | }; |
| 4244 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4245 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4246 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4247 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4248 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4249 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4250 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4251 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4252 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4253 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4254 | |
| 4255 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4256 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4257 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4258 | |
| 4259 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4260 | ASSERT_TRUE(response); |
| 4261 | ASSERT_TRUE(response->headers); |
| 4262 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 4263 | EXPECT_EQ(407, response->headers->response_code()); |
| 4264 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4265 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4266 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4267 | |
| 4268 | LoadTimingInfo load_timing_info; |
| 4269 | // CONNECT requests and responses are handled at the connect job level, so |
| 4270 | // the transaction does not yet have a connection. |
| 4271 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4272 | |
| 4273 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4274 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4275 | response = trans->GetResponseInfo(); |
| 4276 | ASSERT_TRUE(response); |
| 4277 | ASSERT_TRUE(response->headers); |
| 4278 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4279 | EXPECT_EQ(200, response->headers->response_code()); |
| 4280 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4281 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4282 | |
| 4283 | // The password prompt info should not be set. |
| 4284 | EXPECT_FALSE(response->auth_challenge); |
| 4285 | |
| 4286 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4287 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4288 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4289 | |
| 4290 | trans.reset(); |
| 4291 | session->CloseAllConnections(); |
| 4292 | } |
| 4293 | |
| 4294 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4295 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4296 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4297 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4298 | HttpRequestInfo request; |
| 4299 | request.method = "GET"; |
| 4300 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4301 | request.traffic_annotation = |
| 4302 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4303 | |
| 4304 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4305 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4306 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4307 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4308 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4309 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4310 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4311 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4312 | mock_handler->set_allows_default_credentials(true); |
| 4313 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4314 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4315 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4316 | |
| 4317 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4318 | NetLog net_log; |
| 4319 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4320 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4321 | |
| 4322 | // Should try to establish tunnel. |
| 4323 | MockWrite data_writes1[] = { |
| 4324 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4325 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4326 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4327 | |
| 4328 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4329 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4330 | "Proxy-Connection: keep-alive\r\n" |
| 4331 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4332 | }; |
| 4333 | |
| 4334 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4335 | // connection. |
| 4336 | MockRead data_reads1[] = { |
| 4337 | // No credentials. |
| 4338 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4339 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4340 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4341 | }; |
| 4342 | |
| 4343 | // Since the first connection was closed, need to establish another once given |
| 4344 | // credentials. |
| 4345 | MockWrite data_writes2[] = { |
| 4346 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4347 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4348 | "Proxy-Connection: keep-alive\r\n" |
| 4349 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4350 | |
| 4351 | MockWrite("GET / HTTP/1.1\r\n" |
| 4352 | "Host: www.example.org\r\n" |
| 4353 | "Connection: keep-alive\r\n\r\n"), |
| 4354 | }; |
| 4355 | |
| 4356 | MockRead data_reads2[] = { |
| 4357 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4358 | |
| 4359 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4360 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4361 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4362 | MockRead(SYNCHRONOUS, "hello"), |
| 4363 | }; |
| 4364 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4365 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4366 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4367 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4368 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4369 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4370 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4371 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4372 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4373 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4374 | |
| 4375 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4376 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4377 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4378 | |
| 4379 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4380 | ASSERT_TRUE(response); |
| 4381 | ASSERT_TRUE(response->headers); |
| 4382 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4383 | EXPECT_EQ(407, response->headers->response_code()); |
| 4384 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4385 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4386 | EXPECT_FALSE(response->auth_challenge); |
| 4387 | |
| 4388 | LoadTimingInfo load_timing_info; |
| 4389 | // CONNECT requests and responses are handled at the connect job level, so |
| 4390 | // the transaction does not yet have a connection. |
| 4391 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4392 | |
| 4393 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4394 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4395 | |
| 4396 | response = trans->GetResponseInfo(); |
| 4397 | ASSERT_TRUE(response); |
| 4398 | ASSERT_TRUE(response->headers); |
| 4399 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4400 | EXPECT_EQ(200, response->headers->response_code()); |
| 4401 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4402 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4403 | |
| 4404 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4405 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4406 | |
| 4407 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4408 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4409 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4410 | |
| 4411 | trans.reset(); |
| 4412 | session->CloseAllConnections(); |
| 4413 | } |
| 4414 | |
| 4415 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4416 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4417 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4418 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4419 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4420 | HttpRequestInfo request; |
| 4421 | request.method = "GET"; |
| 4422 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4423 | request.traffic_annotation = |
| 4424 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4425 | |
| 4426 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4427 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4428 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4429 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4430 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4431 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4432 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4433 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4434 | mock_handler->set_allows_default_credentials(true); |
| 4435 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4436 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4437 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4438 | |
| 4439 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4440 | NetLog net_log; |
| 4441 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4442 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4443 | |
| 4444 | // Should try to establish tunnel. |
| 4445 | MockWrite data_writes1[] = { |
| 4446 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4447 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4448 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4449 | |
| 4450 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4451 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4452 | "Proxy-Connection: keep-alive\r\n" |
| 4453 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4454 | }; |
| 4455 | |
| 4456 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4457 | // second request is sent. |
| 4458 | MockRead data_reads1[] = { |
| 4459 | // No credentials. |
| 4460 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4461 | MockRead("Content-Length: 0\r\n"), |
| 4462 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4463 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4464 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4465 | }; |
| 4466 | |
| 4467 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4468 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4469 | // request. |
| 4470 | MockWrite data_writes2[] = { |
| 4471 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4472 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4473 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4474 | }; |
| 4475 | |
| 4476 | // The proxy, having had more than enough of us, just hangs up. |
| 4477 | MockRead data_reads2[] = { |
| 4478 | // No credentials. |
| 4479 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4480 | }; |
| 4481 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4482 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4483 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4484 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4485 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4486 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4487 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4488 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4489 | |
| 4490 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4491 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4492 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4493 | |
| 4494 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4495 | ASSERT_TRUE(response); |
| 4496 | ASSERT_TRUE(response->headers); |
| 4497 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4498 | EXPECT_EQ(407, response->headers->response_code()); |
| 4499 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4500 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4501 | EXPECT_FALSE(response->auth_challenge); |
| 4502 | |
| 4503 | LoadTimingInfo load_timing_info; |
| 4504 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4505 | |
| 4506 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4507 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4508 | |
| 4509 | trans.reset(); |
| 4510 | session->CloseAllConnections(); |
| 4511 | } |
| 4512 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4513 | // This test exercises an odd edge case where the proxy closes the connection |
| 4514 | // after the authentication handshake is complete. Presumably this technique is |
| 4515 | // used in lieu of returning a 403 or 5xx status code when the authentication |
| 4516 | // succeeds, but the user is not authorized to connect to the destination |
| 4517 | // server. There's no standard for what a proxy should do to indicate a blocked |
| 4518 | // site. |
| 4519 | TEST_F(HttpNetworkTransactionTest, |
| 4520 | AuthAllowsDefaultCredentialsTunnelConnectionClosesBeforeBody) { |
| 4521 | HttpRequestInfo request; |
| 4522 | request.method = "GET"; |
| 4523 | request.url = GURL("https://www.example.org/"); |
| 4524 | request.traffic_annotation = |
| 4525 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4526 | |
| 4527 | // Configure against proxy server "myproxy:70". |
| 4528 | session_deps_.proxy_resolution_service = |
| 4529 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4530 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4531 | |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 4532 | // When TLS 1.3 is enabled, spurious connections are made as part of the SSL |
| 4533 | // version interference probes. |
| 4534 | // TODO(crbug.com/906668): Correctly handle version interference probes to |
| 4535 | // test TLS 1.3. |
| 4536 | SSLConfig config; |
| 4537 | config.version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
| 4538 | session_deps_.ssl_config_service = |
| 4539 | std::make_unique<TestSSLConfigService>(config); |
| 4540 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4541 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
| 4542 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4543 | |
| 4544 | // Create two mock AuthHandlers. This is because the transaction gets retried |
| 4545 | // after the first ERR_CONNECTION_CLOSED since it's ambiguous whether there |
| 4546 | // was a real network error. |
| 4547 | // |
| 4548 | // The handlers support both default and explicit credentials. The retry |
| 4549 | // mentioned above should be able to reuse the default identity. Thus there |
| 4550 | // should never be a need to prompt for explicit credentials. |
| 4551 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4552 | mock_handler->set_allows_default_credentials(true); |
| 4553 | mock_handler->set_allows_explicit_credentials(true); |
| 4554 | mock_handler->set_connection_based(true); |
| 4555 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4556 | HttpAuth::AUTH_PROXY); |
| 4557 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4558 | mock_handler->set_allows_default_credentials(true); |
| 4559 | mock_handler->set_allows_explicit_credentials(true); |
| 4560 | mock_handler->set_connection_based(true); |
| 4561 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4562 | HttpAuth::AUTH_PROXY); |
| 4563 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4564 | |
| 4565 | NetLog net_log; |
| 4566 | session_deps_.net_log = &net_log; |
| 4567 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4568 | |
| 4569 | // Data for both sockets. |
| 4570 | // |
| 4571 | // Writes are for the tunnel establishment attempts and the |
| 4572 | // authentication handshake. |
| 4573 | MockWrite data_writes1[] = { |
| 4574 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4575 | "Host: www.example.org:443\r\n" |
| 4576 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4577 | |
| 4578 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4579 | "Host: www.example.org:443\r\n" |
| 4580 | "Proxy-Connection: keep-alive\r\n" |
| 4581 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4582 | |
| 4583 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4584 | "Host: www.example.org:443\r\n" |
| 4585 | "Proxy-Connection: keep-alive\r\n" |
| 4586 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4587 | }; |
| 4588 | |
| 4589 | // The server side of the authentication handshake. Note that the response to |
| 4590 | // the final CONNECT request is ERR_CONNECTION_CLOSED. |
| 4591 | MockRead data_reads1[] = { |
| 4592 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4593 | MockRead("Content-Length: 0\r\n"), |
| 4594 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4595 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4596 | |
| 4597 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4598 | MockRead("Content-Length: 0\r\n"), |
| 4599 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4600 | MockRead("Proxy-Authenticate: Mock foo\r\n\r\n"), |
| 4601 | |
| 4602 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4603 | }; |
| 4604 | |
| 4605 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 4606 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4607 | |
| 4608 | // The second socket is for the reconnection attempt. Data is identical to the |
| 4609 | // first attempt. |
| 4610 | StaticSocketDataProvider data2(data_reads1, data_writes1); |
| 4611 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4612 | |
| 4613 | auto trans = |
| 4614 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4615 | |
| 4616 | TestCompletionCallback callback; |
| 4617 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4618 | |
| 4619 | // Two rounds per handshake. After one retry, the error is propagated up the |
| 4620 | // stack. |
| 4621 | for (int i = 0; i < 4; ++i) { |
| 4622 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4623 | |
| 4624 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4625 | ASSERT_TRUE(response); |
| 4626 | ASSERT_TRUE(response->headers); |
| 4627 | EXPECT_EQ(407, response->headers->response_code()); |
| 4628 | ASSERT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4629 | |
| 4630 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4631 | } |
| 4632 | |
| 4633 | // One shall be the number thou shalt retry, and the number of the retrying |
| 4634 | // shall be one. Two shalt thou not retry, neither retry thou zero, excepting |
| 4635 | // that thou then proceed to one. Three is right out. Once the number one, |
| 4636 | // being the first number, be reached, then lobbest thou thy |
| 4637 | // ERR_CONNECTION_CLOSED towards they network transaction, who shall snuff it. |
| 4638 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.GetResult(rv)); |
| 4639 | |
| 4640 | trans.reset(); |
| 4641 | session->CloseAllConnections(); |
| 4642 | } |
| 4643 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4644 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4645 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4646 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4647 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4648 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4649 | HttpRequestInfo request; |
| 4650 | request.method = "GET"; |
| 4651 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4652 | request.traffic_annotation = |
| 4653 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4654 | |
| 4655 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4656 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4657 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4658 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4659 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4660 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4661 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4662 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4663 | mock_handler->set_allows_default_credentials(true); |
| 4664 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4665 | HttpAuth::AUTH_PROXY); |
| 4666 | // Add another handler for the second challenge. It supports default |
| 4667 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4668 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4669 | mock_handler->set_allows_default_credentials(true); |
| 4670 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4671 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4672 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4673 | |
| 4674 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4675 | NetLog net_log; |
| 4676 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4677 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4678 | |
| 4679 | // Should try to establish tunnel. |
| 4680 | MockWrite data_writes1[] = { |
| 4681 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4682 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4683 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4684 | }; |
| 4685 | |
| 4686 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4687 | // connection. |
| 4688 | MockRead data_reads1[] = { |
| 4689 | // No credentials. |
| 4690 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4691 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4692 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4693 | }; |
| 4694 | |
| 4695 | // Since the first connection was closed, need to establish another once given |
| 4696 | // credentials. |
| 4697 | MockWrite data_writes2[] = { |
| 4698 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4699 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4700 | "Proxy-Connection: keep-alive\r\n" |
| 4701 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4702 | }; |
| 4703 | |
| 4704 | MockRead data_reads2[] = { |
| 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 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4710 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4711 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4712 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4713 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4714 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4715 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4716 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4717 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4718 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4719 | |
| 4720 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4721 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4722 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4723 | |
| 4724 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4725 | ASSERT_TRUE(response); |
| 4726 | ASSERT_TRUE(response->headers); |
| 4727 | EXPECT_EQ(407, response->headers->response_code()); |
| 4728 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4729 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4730 | EXPECT_FALSE(response->auth_challenge); |
| 4731 | |
| 4732 | LoadTimingInfo load_timing_info; |
| 4733 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4734 | |
| 4735 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4736 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4737 | response = trans->GetResponseInfo(); |
| 4738 | ASSERT_TRUE(response); |
| 4739 | ASSERT_TRUE(response->headers); |
| 4740 | EXPECT_EQ(407, response->headers->response_code()); |
| 4741 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4742 | EXPECT_TRUE(response->auth_challenge); |
| 4743 | |
| 4744 | trans.reset(); |
| 4745 | session->CloseAllConnections(); |
| 4746 | } |
| 4747 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4748 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4749 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4750 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4751 | // authentication handshake can continue with the same scheme but with a |
| 4752 | // different identity. |
| 4753 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4754 | HttpRequestInfo request; |
| 4755 | request.method = "GET"; |
| 4756 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4757 | request.traffic_annotation = |
| 4758 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4759 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4760 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4761 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4762 | |
| 4763 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4764 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4765 | mock_handler->set_allows_default_credentials(true); |
| 4766 | mock_handler->set_allows_explicit_credentials(true); |
| 4767 | mock_handler->set_connection_based(true); |
| 4768 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4769 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4770 | HttpAuth::AUTH_SERVER); |
| 4771 | |
| 4772 | // Add another handler for the second challenge. It supports default |
| 4773 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4774 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4775 | mock_handler->set_allows_default_credentials(true); |
| 4776 | mock_handler->set_allows_explicit_credentials(true); |
| 4777 | mock_handler->set_connection_based(true); |
| 4778 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4779 | HttpAuth::AUTH_SERVER); |
| 4780 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4781 | |
| 4782 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4783 | |
| 4784 | MockWrite data_writes1[] = { |
| 4785 | MockWrite("GET / HTTP/1.1\r\n" |
| 4786 | "Host: www.example.org\r\n" |
| 4787 | "Connection: keep-alive\r\n\r\n"), |
| 4788 | }; |
| 4789 | |
| 4790 | MockRead data_reads1[] = { |
| 4791 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4792 | "WWW-Authenticate: Mock\r\n" |
| 4793 | "Connection: keep-alive\r\n\r\n"), |
| 4794 | }; |
| 4795 | |
| 4796 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4797 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4798 | // transaction procceds without an authorization header. |
| 4799 | MockWrite data_writes2[] = { |
| 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_reads2[] = { |
| 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 | MockWrite data_writes3[] = { |
| 4812 | MockWrite("GET / HTTP/1.1\r\n" |
| 4813 | "Host: www.example.org\r\n" |
| 4814 | "Connection: keep-alive\r\n" |
| 4815 | "Authorization: auth_token\r\n\r\n"), |
| 4816 | }; |
| 4817 | |
| 4818 | MockRead data_reads3[] = { |
| 4819 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4820 | "Content-Length: 5\r\n" |
| 4821 | "Content-Type: text/plain\r\n" |
| 4822 | "Connection: keep-alive\r\n\r\n" |
| 4823 | "Hello"), |
| 4824 | }; |
| 4825 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4826 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4827 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4828 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4829 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4830 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4831 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4832 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4833 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4834 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4835 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4836 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4837 | |
| 4838 | TestCompletionCallback callback; |
| 4839 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4840 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4841 | |
| 4842 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4843 | ASSERT_TRUE(response); |
| 4844 | ASSERT_TRUE(response->headers); |
| 4845 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4846 | |
| 4847 | // The following three tests assert that an authentication challenge was |
| 4848 | // received and that the stack is ready to respond to the challenge using |
| 4849 | // ambient credentials. |
| 4850 | EXPECT_EQ(401, response->headers->response_code()); |
| 4851 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4852 | EXPECT_FALSE(response->auth_challenge); |
| 4853 | |
| 4854 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4855 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4856 | response = trans->GetResponseInfo(); |
| 4857 | ASSERT_TRUE(response); |
| 4858 | ASSERT_TRUE(response->headers); |
| 4859 | |
| 4860 | // The following three tests assert that an authentication challenge was |
| 4861 | // received and that the stack needs explicit credentials before it is ready |
| 4862 | // to respond to the challenge. |
| 4863 | EXPECT_EQ(401, response->headers->response_code()); |
| 4864 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4865 | EXPECT_TRUE(response->auth_challenge); |
| 4866 | |
| 4867 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4868 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4869 | response = trans->GetResponseInfo(); |
| 4870 | ASSERT_TRUE(response); |
| 4871 | ASSERT_TRUE(response->headers); |
| 4872 | EXPECT_EQ(200, response->headers->response_code()); |
| 4873 | |
| 4874 | trans.reset(); |
| 4875 | session->CloseAllConnections(); |
| 4876 | } |
| 4877 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4878 | // Proxy resolver that returns a proxy with the same host and port for different |
| 4879 | // schemes, based on the path of the URL being requests. |
| 4880 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 4881 | public: |
| 4882 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 4883 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 4884 | |
| 4885 | static std::string ProxyHostPortPairAsString() { return "proxy.test:10000"; } |
| 4886 | |
| 4887 | static HostPortPair ProxyHostPortPair() { |
| 4888 | return HostPortPair::FromString(ProxyHostPortPairAsString()); |
| 4889 | } |
| 4890 | |
| 4891 | // ProxyResolver implementation. |
| 4892 | int GetProxyForURL(const GURL& url, |
| 4893 | ProxyInfo* results, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4894 | CompletionOnceCallback callback, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4895 | std::unique_ptr<Request>* request, |
| 4896 | const NetLogWithSource& /*net_log*/) override { |
| 4897 | *results = ProxyInfo(); |
Ramin Halavati | 921731ea | 2018-03-16 08:24:57 | [diff] [blame] | 4898 | results->set_traffic_annotation( |
| 4899 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4900 | if (url.path() == "/socks4") { |
| 4901 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 4902 | return OK; |
| 4903 | } |
| 4904 | if (url.path() == "/socks5") { |
| 4905 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 4906 | return OK; |
| 4907 | } |
| 4908 | if (url.path() == "/http") { |
| 4909 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 4910 | return OK; |
| 4911 | } |
| 4912 | if (url.path() == "/https") { |
| 4913 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 4914 | return OK; |
| 4915 | } |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 4916 | if (url.path() == "/https_trusted") { |
| 4917 | results->UseProxyServer(ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 4918 | ProxyHostPortPair(), |
| 4919 | true /* is_trusted_proxy */)); |
| 4920 | return OK; |
| 4921 | } |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4922 | NOTREACHED(); |
| 4923 | return ERR_NOT_IMPLEMENTED; |
| 4924 | } |
| 4925 | |
| 4926 | private: |
| 4927 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 4928 | }; |
| 4929 | |
| 4930 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 4931 | : public ProxyResolverFactory { |
| 4932 | public: |
| 4933 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 4934 | : ProxyResolverFactory(false) {} |
| 4935 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4936 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 4937 | std::unique_ptr<ProxyResolver>* resolver, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4938 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4939 | std::unique_ptr<Request>* request) override { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4940 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 4941 | return OK; |
| 4942 | } |
| 4943 | |
| 4944 | private: |
| 4945 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 4946 | }; |
| 4947 | |
| 4948 | // 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] | 4949 | // same address, the connections are not grouped together. i.e., a request to |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4950 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 4951 | // request to foo.com using proxy.com as an HTTP proxy. |
| 4952 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4953 | session_deps_.proxy_resolution_service = |
| 4954 | std::make_unique<ProxyResolutionService>( |
| 4955 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 4956 | ProxyConfig::CreateAutoDetect(), TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 4957 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
| 4958 | nullptr); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4959 | |
| 4960 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4961 | |
| 4962 | MockWrite socks_writes[] = { |
| 4963 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 4964 | kSOCKS4OkRequestLocalHostPort80Length), |
| 4965 | MockWrite(SYNCHRONOUS, |
| 4966 | "GET /socks4 HTTP/1.1\r\n" |
| 4967 | "Host: test\r\n" |
| 4968 | "Connection: keep-alive\r\n\r\n"), |
| 4969 | }; |
| 4970 | MockRead socks_reads[] = { |
| 4971 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 4972 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4973 | "Connection: keep-alive\r\n" |
| 4974 | "Content-Length: 15\r\n\r\n" |
| 4975 | "SOCKS4 Response"), |
| 4976 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4977 | StaticSocketDataProvider socks_data(socks_reads, socks_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4978 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 4979 | |
| 4980 | const char kSOCKS5Request[] = { |
| 4981 | 0x05, // Version |
| 4982 | 0x01, // Command (CONNECT) |
| 4983 | 0x00, // Reserved |
| 4984 | 0x03, // Address type (DOMAINNAME) |
| 4985 | 0x04, // Length of domain (4) |
| 4986 | 't', 'e', 's', 't', // Domain string |
| 4987 | 0x00, 0x50, // 16-bit port (80) |
| 4988 | }; |
| 4989 | MockWrite socks5_writes[] = { |
| 4990 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 4991 | MockWrite(ASYNC, kSOCKS5Request, base::size(kSOCKS5Request)), |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4992 | MockWrite(SYNCHRONOUS, |
| 4993 | "GET /socks5 HTTP/1.1\r\n" |
| 4994 | "Host: test\r\n" |
| 4995 | "Connection: keep-alive\r\n\r\n"), |
| 4996 | }; |
| 4997 | MockRead socks5_reads[] = { |
| 4998 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 4999 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 5000 | MockRead("HTTP/1.0 200 OK\r\n" |
| 5001 | "Connection: keep-alive\r\n" |
| 5002 | "Content-Length: 15\r\n\r\n" |
| 5003 | "SOCKS5 Response"), |
| 5004 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5005 | StaticSocketDataProvider socks5_data(socks5_reads, socks5_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5006 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 5007 | |
| 5008 | MockWrite http_writes[] = { |
| 5009 | MockWrite(SYNCHRONOUS, |
| 5010 | "GET http://test/http HTTP/1.1\r\n" |
| 5011 | "Host: test\r\n" |
| 5012 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5013 | }; |
| 5014 | MockRead http_reads[] = { |
| 5015 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5016 | "Proxy-Connection: keep-alive\r\n" |
| 5017 | "Content-Length: 13\r\n\r\n" |
| 5018 | "HTTP Response"), |
| 5019 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5020 | StaticSocketDataProvider http_data(http_reads, http_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5021 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 5022 | |
| 5023 | MockWrite https_writes[] = { |
| 5024 | MockWrite(SYNCHRONOUS, |
| 5025 | "GET http://test/https HTTP/1.1\r\n" |
| 5026 | "Host: test\r\n" |
| 5027 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5028 | }; |
| 5029 | MockRead https_reads[] = { |
| 5030 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5031 | "Proxy-Connection: keep-alive\r\n" |
| 5032 | "Content-Length: 14\r\n\r\n" |
| 5033 | "HTTPS Response"), |
| 5034 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5035 | StaticSocketDataProvider https_data(https_reads, https_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5036 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 5037 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 5038 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5039 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5040 | MockWrite https_trusted_writes[] = { |
| 5041 | MockWrite(SYNCHRONOUS, |
| 5042 | "GET http://test/https_trusted HTTP/1.1\r\n" |
| 5043 | "Host: test\r\n" |
| 5044 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5045 | }; |
| 5046 | MockRead https_trusted_reads[] = { |
| 5047 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5048 | "Proxy-Connection: keep-alive\r\n" |
| 5049 | "Content-Length: 22\r\n\r\n" |
| 5050 | "HTTPS Trusted Response"), |
| 5051 | }; |
| 5052 | StaticSocketDataProvider trusted_https_data(https_trusted_reads, |
| 5053 | https_trusted_writes); |
| 5054 | session_deps_.socket_factory->AddSocketDataProvider(&trusted_https_data); |
| 5055 | SSLSocketDataProvider ssl2(SYNCHRONOUS, OK); |
| 5056 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 5057 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5058 | struct TestCase { |
| 5059 | GURL url; |
| 5060 | std::string expected_response; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5061 | // 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] | 5062 | // after the test. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5063 | int expected_idle_socks4_sockets; |
| 5064 | int expected_idle_socks5_sockets; |
| 5065 | // How many idle sockets there should be in the HTTP/HTTPS proxy socket |
| 5066 | // pools after the test. |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5067 | int expected_idle_http_sockets; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5068 | int expected_idle_https_sockets; |
| 5069 | // How many idle sockets there should be in the HTTPS proxy socket pool with |
| 5070 | // the ProxyServer's |is_trusted_proxy| bit set after the test. |
| 5071 | int expected_idle_trusted_https_sockets; |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5072 | } const kTestCases[] = { |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5073 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0, 0, 0, 0}, |
| 5074 | {GURL("http://test/socks5"), "SOCKS5 Response", 1, 1, 0, 0, 0}, |
| 5075 | {GURL("http://test/http"), "HTTP Response", 1, 1, 1, 0, 0}, |
| 5076 | {GURL("http://test/https"), "HTTPS Response", 1, 1, 1, 1, 0}, |
| 5077 | {GURL("http://test/https_trusted"), "HTTPS Trusted Response", 1, 1, 1, 1, |
| 5078 | 1}, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5079 | }; |
| 5080 | |
| 5081 | for (const auto& test_case : kTestCases) { |
| 5082 | HttpRequestInfo request; |
| 5083 | request.method = "GET"; |
| 5084 | request.url = test_case.url; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5085 | request.traffic_annotation = |
| 5086 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5087 | std::unique_ptr<HttpNetworkTransaction> trans = |
| 5088 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 5089 | session.get()); |
| 5090 | TestCompletionCallback callback; |
| 5091 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 5092 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5093 | |
| 5094 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5095 | ASSERT_TRUE(response); |
| 5096 | ASSERT_TRUE(response->headers); |
| 5097 | EXPECT_EQ(200, response->headers->response_code()); |
| 5098 | std::string response_data; |
| 5099 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 5100 | EXPECT_EQ(test_case.expected_response, response_data); |
| 5101 | |
| 5102 | // Return the socket to the socket pool, so can make sure it's not used for |
| 5103 | // the next requests. |
| 5104 | trans.reset(); |
| 5105 | base::RunLoop().RunUntilIdle(); |
| 5106 | |
| 5107 | // Check the number of idle sockets in the pool, to make sure that used |
| 5108 | // sockets are indeed being returned to the socket pool. If each request |
| 5109 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 5110 | // pass. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5111 | EXPECT_EQ(test_case.expected_idle_socks4_sockets, |
| 5112 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5113 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5114 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5115 | ProxyServer(ProxyServer::SCHEME_SOCKS4, |
| 5116 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5117 | ProxyHostPortPair())) |
| 5118 | ->IdleSocketCount()); |
| 5119 | EXPECT_EQ(test_case.expected_idle_socks5_sockets, |
| 5120 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5121 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5122 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5123 | ProxyServer(ProxyServer::SCHEME_SOCKS5, |
| 5124 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5125 | ProxyHostPortPair())) |
| 5126 | ->IdleSocketCount()); |
| 5127 | EXPECT_EQ(test_case.expected_idle_http_sockets, |
| 5128 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5129 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5130 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5131 | ProxyServer(ProxyServer::SCHEME_HTTP, |
| 5132 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5133 | ProxyHostPortPair())) |
| 5134 | ->IdleSocketCount()); |
| 5135 | EXPECT_EQ(test_case.expected_idle_https_sockets, |
| 5136 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5137 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5138 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5139 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5140 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5141 | ProxyHostPortPair())) |
| 5142 | ->IdleSocketCount()); |
| 5143 | EXPECT_EQ(test_case.expected_idle_trusted_https_sockets, |
| 5144 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5145 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5146 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5147 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5148 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5149 | ProxyHostPortPair(), |
| 5150 | true /* is_trusted_proxy */)) |
| 5151 | ->IdleSocketCount()); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5152 | } |
| 5153 | } |
| 5154 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5155 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5156 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5157 | HttpRequestInfo request1; |
| 5158 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5159 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5160 | request1.traffic_annotation = |
| 5161 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5162 | |
| 5163 | HttpRequestInfo request2; |
| 5164 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5165 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5166 | request2.traffic_annotation = |
| 5167 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5168 | |
| 5169 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5170 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5171 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5172 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5173 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5174 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5175 | |
| 5176 | // Since we have proxy, should try to establish tunnel. |
| 5177 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5178 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5179 | "Host: www.example.org:443\r\n" |
| 5180 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5181 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5182 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5183 | "Host: www.example.org\r\n" |
| 5184 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5185 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5186 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5187 | "Host: www.example.org\r\n" |
| 5188 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5189 | }; |
| 5190 | |
| 5191 | // The proxy responds to the connect with a 407, using a persistent |
| 5192 | // connection. |
| 5193 | MockRead data_reads1[] = { |
| 5194 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5195 | |
| 5196 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5197 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5198 | MockRead(SYNCHRONOUS, "1"), |
| 5199 | |
| 5200 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5201 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5202 | MockRead(SYNCHRONOUS, "22"), |
| 5203 | }; |
| 5204 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5205 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5206 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5207 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5208 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5209 | |
| 5210 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5211 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5212 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5213 | |
| 5214 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5215 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5216 | |
| 5217 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5218 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5219 | |
| 5220 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5221 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5222 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5223 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5224 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5225 | |
| 5226 | LoadTimingInfo load_timing_info1; |
| 5227 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5228 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5229 | |
| 5230 | trans1.reset(); |
| 5231 | |
| 5232 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5233 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5234 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5235 | |
| 5236 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5237 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5238 | |
| 5239 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5240 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5241 | |
| 5242 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5243 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5244 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5245 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5246 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5247 | |
| 5248 | LoadTimingInfo load_timing_info2; |
| 5249 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5250 | TestLoadTimingReused(load_timing_info2); |
| 5251 | |
| 5252 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5253 | |
| 5254 | trans2.reset(); |
| 5255 | session->CloseAllConnections(); |
| 5256 | } |
| 5257 | |
| 5258 | // 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] | 5259 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5260 | HttpRequestInfo request1; |
| 5261 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5262 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5263 | request1.traffic_annotation = |
| 5264 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5265 | |
| 5266 | HttpRequestInfo request2; |
| 5267 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5268 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5269 | request2.traffic_annotation = |
| 5270 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5271 | |
| 5272 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5273 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5274 | ProxyResolutionService::CreateFixedFromPacResult( |
| 5275 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5276 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5277 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5278 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5279 | |
| 5280 | // Since we have proxy, should try to establish tunnel. |
| 5281 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5282 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5283 | "Host: www.example.org:443\r\n" |
| 5284 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5285 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5286 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5287 | "Host: www.example.org\r\n" |
| 5288 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5289 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5290 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5291 | "Host: www.example.org\r\n" |
| 5292 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5293 | }; |
| 5294 | |
| 5295 | // The proxy responds to the connect with a 407, using a persistent |
| 5296 | // connection. |
| 5297 | MockRead data_reads1[] = { |
| 5298 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5299 | |
| 5300 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5301 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5302 | MockRead(SYNCHRONOUS, "1"), |
| 5303 | |
| 5304 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5305 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5306 | MockRead(SYNCHRONOUS, "22"), |
| 5307 | }; |
| 5308 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5309 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5310 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5311 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5312 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5313 | |
| 5314 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5315 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5316 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5317 | |
| 5318 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5319 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5320 | |
| 5321 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5322 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5323 | |
| 5324 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5325 | ASSERT_TRUE(response1); |
| 5326 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5327 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5328 | |
| 5329 | LoadTimingInfo load_timing_info1; |
| 5330 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5331 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 5332 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 5333 | |
| 5334 | trans1.reset(); |
| 5335 | |
| 5336 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5337 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5338 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5339 | |
| 5340 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5341 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5342 | |
| 5343 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5344 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5345 | |
| 5346 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5347 | ASSERT_TRUE(response2); |
| 5348 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5349 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5350 | |
| 5351 | LoadTimingInfo load_timing_info2; |
| 5352 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5353 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 5354 | |
| 5355 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5356 | |
| 5357 | trans2.reset(); |
| 5358 | session->CloseAllConnections(); |
| 5359 | } |
| 5360 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5361 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5362 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5363 | HttpRequestInfo request; |
| 5364 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5365 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5366 | request.traffic_annotation = |
| 5367 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5368 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5369 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5370 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5371 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5372 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5373 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5374 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5375 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5376 | // Since we have proxy, should use full url |
| 5377 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5378 | MockWrite( |
| 5379 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5380 | "Host: www.example.org\r\n" |
| 5381 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5382 | }; |
| 5383 | |
| 5384 | MockRead data_reads1[] = { |
| 5385 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5386 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5387 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5388 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5389 | }; |
| 5390 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5391 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5392 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5393 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5394 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5395 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5396 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5397 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5398 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5399 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5400 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5401 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5402 | |
| 5403 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5404 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5405 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5406 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5407 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5408 | TestLoadTimingNotReused(load_timing_info, |
| 5409 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5410 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5411 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5412 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5413 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5414 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5415 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5416 | EXPECT_EQ(200, response->headers->response_code()); |
| 5417 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5418 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5419 | |
| 5420 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5421 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5422 | } |
| 5423 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5424 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5425 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5426 | HttpRequestInfo request; |
| 5427 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5428 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5429 | request.traffic_annotation = |
| 5430 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5431 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5432 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5433 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5434 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5435 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5436 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5437 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5438 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5439 | // fetch http://www.example.org/ via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5440 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5441 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5442 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5443 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5444 | spdy::SpdySerializedFrame resp( |
| 5445 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 5446 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5447 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5448 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5449 | }; |
| 5450 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5451 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5452 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5453 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5454 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5455 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5456 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5457 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5458 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5459 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5460 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5461 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5462 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5463 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5464 | |
| 5465 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5466 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5467 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5468 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5469 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5470 | TestLoadTimingNotReused(load_timing_info, |
| 5471 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5472 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5473 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5474 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5475 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5476 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5477 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5478 | |
| 5479 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5480 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5481 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5482 | } |
| 5483 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5484 | // Verifies that a session which races and wins against the owning transaction |
| 5485 | // (completing prior to host resolution), doesn't fail the transaction. |
| 5486 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5487 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5488 | HttpRequestInfo request; |
| 5489 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5490 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5491 | request.traffic_annotation = |
| 5492 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5493 | |
| 5494 | // Configure SPDY proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5495 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5496 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5497 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5498 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5499 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5500 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5501 | // Fetch http://www.example.org/ through the SPDY proxy. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5502 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5503 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5504 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5505 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5506 | spdy::SpdySerializedFrame resp( |
| 5507 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5508 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5509 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5510 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5511 | }; |
| 5512 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5513 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5514 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5515 | |
| 5516 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5517 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5518 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5519 | |
| 5520 | TestCompletionCallback callback1; |
| 5521 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5522 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5523 | |
| 5524 | // Stall the hostname resolution begun by the transaction. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5525 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5526 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5527 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5528 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5529 | |
| 5530 | // Race a session to the proxy, which completes first. |
| 5531 | session_deps_.host_resolver->set_ondemand_mode(false); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 5532 | SpdySessionKey key(HostPortPair("proxy", 70), ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 5533 | PRIVACY_MODE_DISABLED, |
| 5534 | SpdySessionKey::IsProxySession::kTrue, SocketTag()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5535 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 5536 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5537 | |
| 5538 | // Unstall the resolution begun by the transaction. |
| 5539 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5540 | session_deps_.host_resolver->ResolveAllPending(); |
| 5541 | |
| 5542 | EXPECT_FALSE(callback1.have_result()); |
| 5543 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5544 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5545 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5546 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5547 | ASSERT_TRUE(response); |
| 5548 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5549 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5550 | |
| 5551 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5552 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5553 | EXPECT_EQ(kUploadData, response_data); |
| 5554 | } |
| 5555 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5556 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5557 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5558 | HttpRequestInfo request; |
| 5559 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5560 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5561 | request.traffic_annotation = |
| 5562 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5563 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5564 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5565 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5566 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5567 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5568 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5569 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5570 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5571 | // The first request will be a bare GET, the second request will be a |
| 5572 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5573 | spdy_util_.set_default_url(request.url); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5574 | spdy::SpdySerializedFrame req_get( |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5575 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5576 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5577 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5578 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5579 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5580 | spdy::SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5581 | kExtraAuthorizationHeaders, base::size(kExtraAuthorizationHeaders) / 2, 3, |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5582 | LOWEST)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5583 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5584 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5585 | }; |
| 5586 | |
| 5587 | // The first response is a 407 proxy authentication challenge, and the second |
| 5588 | // response will be a 200 response since the second request includes a valid |
| 5589 | // Authorization header. |
| 5590 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5591 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5592 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5593 | spdy::SpdySerializedFrame resp_authentication( |
| 5594 | spdy_util_.ConstructSpdyReplyError( |
| 5595 | "407", kExtraAuthenticationHeaders, |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5596 | base::size(kExtraAuthenticationHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5597 | spdy::SpdySerializedFrame body_authentication( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5598 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5599 | spdy::SpdySerializedFrame resp_data( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5600 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5601 | spdy::SpdySerializedFrame body_data( |
| 5602 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5603 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5604 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5605 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5606 | CreateMockRead(resp_data, 4), |
| 5607 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5608 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5609 | }; |
| 5610 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5611 | SequencedSocketData data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5612 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5613 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5614 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5615 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5616 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5617 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5618 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5619 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5620 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5621 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5622 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5623 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5624 | |
| 5625 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5626 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5627 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5628 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5629 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5630 | ASSERT_TRUE(response); |
| 5631 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5632 | EXPECT_EQ(407, response->headers->response_code()); |
| 5633 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5634 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5635 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5636 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5637 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5638 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5639 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5640 | |
| 5641 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5642 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5643 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5644 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5645 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5646 | ASSERT_TRUE(response_restart); |
| 5647 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5648 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5649 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5650 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5651 | } |
| 5652 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5653 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5654 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5655 | HttpRequestInfo request; |
| 5656 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5657 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5658 | request.traffic_annotation = |
| 5659 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5660 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5661 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5662 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5663 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5664 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5665 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5666 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5667 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5668 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5669 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5670 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5671 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5672 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5673 | HostPortPair("www.example.org", 443))); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5674 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5675 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5676 | const char get[] = |
| 5677 | "GET / HTTP/1.1\r\n" |
| 5678 | "Host: www.example.org\r\n" |
| 5679 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5680 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5681 | spdy_util_.ConstructSpdyDataFrame(1, get, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5682 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5683 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5684 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 5685 | "Content-Length: 10\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5686 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5687 | spdy_util_.ConstructSpdyDataFrame(1, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5688 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5689 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5690 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5691 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5692 | |
| 5693 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5694 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5695 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5696 | }; |
| 5697 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5698 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5699 | CreateMockRead(conn_resp, 1, ASYNC), |
| 5700 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 5701 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 5702 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5703 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5704 | }; |
| 5705 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5706 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5707 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5708 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5709 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5710 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5711 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5712 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5713 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5714 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5715 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5716 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5717 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5718 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5719 | |
| 5720 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5721 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5722 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5723 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5724 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5725 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5726 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5727 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5728 | ASSERT_TRUE(response); |
| 5729 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5730 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5731 | |
| 5732 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5733 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5734 | EXPECT_EQ("1234567890", response_data); |
| 5735 | } |
| 5736 | |
| 5737 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5738 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5739 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5740 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5741 | HttpRequestInfo request; |
| 5742 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5743 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5744 | request.traffic_annotation = |
| 5745 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5746 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5747 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5748 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5749 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5750 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5751 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5752 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5753 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5754 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5755 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5756 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5757 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5758 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5759 | HostPortPair("www.example.org", 443))); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5760 | // fetch https://www.example.org/ via SPDY |
| 5761 | const char kMyUrl[] = "https://www.example.org/"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5762 | spdy::SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5763 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5764 | spdy::SpdySerializedFrame wrapped_get( |
| 5765 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 5766 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5767 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5768 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5769 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5770 | spdy::SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5771 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5772 | spdy::SpdySerializedFrame body( |
| 5773 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5774 | spdy::SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5775 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5776 | spdy::SpdySerializedFrame window_update_get_resp( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5777 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5778 | spdy::SpdySerializedFrame window_update_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5779 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5780 | |
| 5781 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5782 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5783 | CreateMockWrite(window_update_get_resp, 6), |
| 5784 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5785 | }; |
| 5786 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5787 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5788 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5789 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5790 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5791 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5792 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5793 | }; |
| 5794 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5795 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5796 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5797 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5798 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5799 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5800 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5801 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5802 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5803 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5804 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5805 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5806 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5807 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5808 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5809 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5810 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5811 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5812 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5813 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5814 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5815 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5816 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5817 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5818 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5819 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5820 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5821 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5822 | ASSERT_TRUE(response); |
| 5823 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5824 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5825 | |
| 5826 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5827 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5828 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5829 | } |
| 5830 | |
| 5831 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5832 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5833 | HttpRequestInfo request; |
| 5834 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5835 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5836 | request.traffic_annotation = |
| 5837 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5838 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5839 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5840 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5841 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5842 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5843 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5844 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5845 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5846 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5847 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5848 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5849 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5850 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5851 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5852 | spdy::SpdySerializedFrame get( |
| 5853 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5854 | |
| 5855 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5856 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5857 | }; |
| 5858 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5859 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
| 5860 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5861 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5862 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5863 | }; |
| 5864 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5865 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5866 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5867 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5868 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5869 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5870 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5871 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5872 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5873 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5874 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5875 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5876 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5877 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5878 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5879 | |
| 5880 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5881 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5882 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5883 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5884 | } |
| 5885 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5886 | // Test the case where a proxied H2 session doesn't exist when an auth challenge |
| 5887 | // is observed, but does exist by the time auth credentials are provided. |
| 5888 | // Proxy-Connection: Close is used so that there's a second DNS lookup, which is |
| 5889 | // what causes the existing H2 session to be noticed and reused. |
| 5890 | TEST_F(HttpNetworkTransactionTest, ProxiedH2SessionAppearsDuringAuth) { |
| 5891 | ProxyConfig proxy_config; |
| 5892 | proxy_config.set_auto_detect(true); |
| 5893 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 5894 | |
| 5895 | CapturingProxyResolver capturing_proxy_resolver; |
| 5896 | capturing_proxy_resolver.set_proxy_server( |
| 5897 | ProxyServer(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 70))); |
| 5898 | session_deps_.proxy_resolution_service = |
| 5899 | std::make_unique<ProxyResolutionService>( |
| 5900 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 5901 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 5902 | std::make_unique<CapturingProxyResolverFactory>( |
| 5903 | &capturing_proxy_resolver), |
| 5904 | nullptr); |
| 5905 | |
| 5906 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 5907 | |
| 5908 | const char kMyUrl[] = "https://www.example.org/"; |
| 5909 | spdy::SpdySerializedFrame get(spdy_util_.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 5910 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5911 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5912 | spdy::SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 5913 | |
| 5914 | spdy_util_.UpdateWithStreamDestruction(1); |
| 5915 | spdy::SpdySerializedFrame get2( |
| 5916 | spdy_util_.ConstructSpdyGet(kMyUrl, 3, LOWEST)); |
| 5917 | spdy::SpdySerializedFrame get_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5918 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5919 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
| 5920 | |
| 5921 | MockWrite auth_challenge_writes[] = { |
| 5922 | MockWrite(ASYNC, 0, |
| 5923 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5924 | "Host: www.example.org:443\r\n" |
| 5925 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5926 | }; |
| 5927 | |
| 5928 | MockRead auth_challenge_reads[] = { |
| 5929 | MockRead(ASYNC, 1, |
| 5930 | "HTTP/1.1 407 Authentication Required\r\n" |
| 5931 | "Content-Length: 0\r\n" |
| 5932 | "Proxy-Connection: close\r\n" |
| 5933 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
| 5934 | }; |
| 5935 | |
| 5936 | MockWrite spdy_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" |
| 5941 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5942 | CreateMockWrite(get, 2), |
| 5943 | CreateMockWrite(get2, 5), |
| 5944 | }; |
| 5945 | |
| 5946 | MockRead spdy_reads[] = { |
| 5947 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 5948 | CreateMockRead(get_resp, 3, ASYNC), |
| 5949 | CreateMockRead(body, 4, ASYNC), |
| 5950 | CreateMockRead(get_resp2, 6, ASYNC), |
| 5951 | CreateMockRead(body2, 7, ASYNC), |
| 5952 | |
| 5953 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8), |
| 5954 | }; |
| 5955 | |
| 5956 | SequencedSocketData auth_challenge1(auth_challenge_reads, |
| 5957 | auth_challenge_writes); |
| 5958 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge1); |
| 5959 | |
| 5960 | SequencedSocketData auth_challenge2(auth_challenge_reads, |
| 5961 | auth_challenge_writes); |
| 5962 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge2); |
| 5963 | |
| 5964 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
| 5965 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5966 | |
| 5967 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5968 | ssl.next_proto = kProtoHTTP2; |
| 5969 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5970 | |
| 5971 | TestCompletionCallback callback; |
| 5972 | std::string response_data; |
| 5973 | |
| 5974 | // Run first request until an auth challenge is observed. |
| 5975 | HttpRequestInfo request1; |
| 5976 | request1.method = "GET"; |
| 5977 | request1.url = GURL(kMyUrl); |
| 5978 | request1.traffic_annotation = |
| 5979 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5980 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 5981 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 5982 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5983 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 5984 | ASSERT_TRUE(response); |
| 5985 | ASSERT_TRUE(response->headers); |
| 5986 | EXPECT_EQ(407, response->headers->response_code()); |
| 5987 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5988 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 5989 | |
| 5990 | // Run second request until an auth challenge is observed. |
| 5991 | HttpRequestInfo request2; |
| 5992 | request2.method = "GET"; |
| 5993 | request2.url = GURL(kMyUrl); |
| 5994 | request2.traffic_annotation = |
| 5995 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5996 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 5997 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 5998 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5999 | response = trans2.GetResponseInfo(); |
| 6000 | ASSERT_TRUE(response); |
| 6001 | ASSERT_TRUE(response->headers); |
| 6002 | EXPECT_EQ(407, response->headers->response_code()); |
| 6003 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6004 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 6005 | |
| 6006 | // Now provide credentials for the first request, and wait for it to complete. |
| 6007 | rv = trans1.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6008 | rv = callback.GetResult(rv); |
| 6009 | EXPECT_THAT(rv, IsOk()); |
| 6010 | response = trans1.GetResponseInfo(); |
| 6011 | ASSERT_TRUE(response); |
| 6012 | ASSERT_TRUE(response->headers); |
| 6013 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6014 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6015 | EXPECT_EQ(kUploadData, response_data); |
| 6016 | |
| 6017 | // Now provide credentials for the second request. It should notice the |
| 6018 | // existing session, and reuse it. |
| 6019 | rv = trans2.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6020 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6021 | response = trans2.GetResponseInfo(); |
| 6022 | ASSERT_TRUE(response); |
| 6023 | ASSERT_TRUE(response->headers); |
| 6024 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6025 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6026 | EXPECT_EQ(kUploadData, response_data); |
| 6027 | } |
| 6028 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6029 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6030 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6031 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6032 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 6033 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6034 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6035 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6036 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6037 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6038 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6039 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6040 | |
| 6041 | HttpRequestInfo request1; |
| 6042 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6043 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6044 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6045 | request1.traffic_annotation = |
| 6046 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6047 | |
| 6048 | HttpRequestInfo request2; |
| 6049 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6050 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6051 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6052 | request2.traffic_annotation = |
| 6053 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6054 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6055 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6056 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6057 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6058 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6059 | spdy::SpdySerializedFrame conn_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6060 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6061 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6062 | // Fetch https://www.example.org/ via HTTP. |
| 6063 | const char get1[] = |
| 6064 | "GET / HTTP/1.1\r\n" |
| 6065 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6066 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6067 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6068 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6069 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6070 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6071 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6072 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6073 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6074 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6075 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6076 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6077 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6078 | // CONNECT to mail.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6079 | spdy::SpdyHeaderBlock connect2_block; |
| 6080 | connect2_block[spdy::kHttp2MethodHeader] = "CONNECT"; |
| 6081 | connect2_block[spdy::kHttp2AuthorityHeader] = "mail.example.org:443"; |
| 6082 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6083 | 3, std::move(connect2_block), HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6084 | false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 6085 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6086 | spdy::SpdySerializedFrame conn_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6087 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6088 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6089 | // Fetch https://mail.example.org/ via HTTP. |
| 6090 | const char get2[] = |
| 6091 | "GET / HTTP/1.1\r\n" |
| 6092 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6093 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6094 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6095 | spdy_util_.ConstructSpdyDataFrame(3, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6096 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6097 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6098 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6099 | spdy_util_.ConstructSpdyDataFrame(3, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6100 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6101 | spdy_util_.ConstructSpdyDataFrame(3, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6102 | |
| 6103 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6104 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6105 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6106 | }; |
| 6107 | |
| 6108 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6109 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6110 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 6111 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 6112 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 6113 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 6114 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 6115 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6116 | }; |
| 6117 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6118 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6119 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6120 | |
| 6121 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6122 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6123 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6124 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6125 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6126 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6127 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6128 | |
| 6129 | TestCompletionCallback callback; |
| 6130 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6131 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6132 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6133 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6134 | |
| 6135 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6136 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6137 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6138 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6139 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6140 | ASSERT_TRUE(response); |
| 6141 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6142 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6143 | |
| 6144 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6145 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6146 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6147 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6148 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6149 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6150 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6151 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6152 | |
| 6153 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6154 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6155 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 6156 | // to be created, so the socket's load timing looks like a fresh connection. |
| 6157 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6158 | |
| 6159 | // The requests should have different IDs, since they each are using their own |
| 6160 | // separate stream. |
| 6161 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6162 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6163 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6164 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6165 | } |
| 6166 | |
| 6167 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6168 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6169 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6170 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 6171 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6172 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6173 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6174 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6175 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6176 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6177 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6178 | |
| 6179 | HttpRequestInfo request1; |
| 6180 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6181 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6182 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6183 | request1.traffic_annotation = |
| 6184 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6185 | |
| 6186 | HttpRequestInfo request2; |
| 6187 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6188 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6189 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6190 | request2.traffic_annotation = |
| 6191 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6192 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6193 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6194 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6195 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6196 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6197 | spdy::SpdySerializedFrame conn_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6198 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6199 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6200 | // Fetch https://www.example.org/ via HTTP. |
| 6201 | const char get1[] = |
| 6202 | "GET / HTTP/1.1\r\n" |
| 6203 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6204 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6205 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6206 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6207 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6208 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6209 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6210 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6211 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6212 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6213 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6214 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6215 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6216 | // Fetch https://www.example.org/2 via HTTP. |
| 6217 | const char get2[] = |
| 6218 | "GET /2 HTTP/1.1\r\n" |
| 6219 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6220 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6221 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6222 | spdy_util_.ConstructSpdyDataFrame(1, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6223 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6224 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6225 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6226 | spdy_util_.ConstructSpdyDataFrame(1, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6227 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6228 | spdy_util_.ConstructSpdyDataFrame(1, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6229 | |
| 6230 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6231 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6232 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6233 | }; |
| 6234 | |
| 6235 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6236 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6237 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6238 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6239 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6240 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6241 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6242 | }; |
| 6243 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6244 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6245 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6246 | |
| 6247 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6248 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6249 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6250 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6251 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6252 | |
| 6253 | TestCompletionCallback callback; |
| 6254 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6255 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6256 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6257 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6258 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6259 | |
| 6260 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6261 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6262 | |
| 6263 | LoadTimingInfo load_timing_info; |
| 6264 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6265 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6266 | |
| 6267 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6268 | ASSERT_TRUE(response); |
| 6269 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6270 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6271 | |
| 6272 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6273 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6274 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6275 | trans.reset(); |
| 6276 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6277 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6278 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6279 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6280 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6281 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6282 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6283 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6284 | |
| 6285 | LoadTimingInfo load_timing_info2; |
| 6286 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 6287 | TestLoadTimingReused(load_timing_info2); |
| 6288 | |
| 6289 | // The requests should have the same ID. |
| 6290 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6291 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6292 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6293 | } |
| 6294 | |
| 6295 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 6296 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6297 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6298 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6299 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6300 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6301 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6302 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6303 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6304 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6305 | |
| 6306 | HttpRequestInfo request1; |
| 6307 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6308 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6309 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6310 | request1.traffic_annotation = |
| 6311 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6312 | |
| 6313 | HttpRequestInfo request2; |
| 6314 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6315 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6316 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6317 | request2.traffic_annotation = |
| 6318 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6319 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6320 | // http://www.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6321 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6322 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6323 | spdy::SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6324 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6325 | spdy::SpdySerializedFrame get_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6326 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6327 | spdy::SpdySerializedFrame body1( |
| 6328 | spdy_util_.ConstructSpdyDataFrame(1, "1", true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 6329 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6330 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6331 | // http://mail.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6332 | spdy::SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6333 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6334 | spdy::SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6335 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6336 | spdy::SpdySerializedFrame get_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6337 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6338 | spdy::SpdySerializedFrame body2( |
| 6339 | spdy_util_.ConstructSpdyDataFrame(3, "22", true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6340 | |
| 6341 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6342 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6343 | }; |
| 6344 | |
| 6345 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6346 | CreateMockRead(get_resp1, 1, ASYNC), |
| 6347 | CreateMockRead(body1, 2, ASYNC), |
| 6348 | CreateMockRead(get_resp2, 4, ASYNC), |
| 6349 | CreateMockRead(body2, 5, ASYNC), |
| 6350 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6351 | }; |
| 6352 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6353 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6354 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6355 | |
| 6356 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6357 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6358 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6359 | |
| 6360 | TestCompletionCallback callback; |
| 6361 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6362 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6363 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6364 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6365 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6366 | |
| 6367 | LoadTimingInfo load_timing_info; |
| 6368 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6369 | TestLoadTimingNotReused(load_timing_info, |
| 6370 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6371 | |
| 6372 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6373 | ASSERT_TRUE(response); |
| 6374 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6375 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6376 | |
| 6377 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6378 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6379 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 6380 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6381 | // Delete the first request, so the second one can reuse the socket. |
| 6382 | trans.reset(); |
| 6383 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6384 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6385 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6386 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6387 | |
| 6388 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6389 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6390 | TestLoadTimingReused(load_timing_info2); |
| 6391 | |
| 6392 | // The requests should have the same ID. |
| 6393 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6394 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6395 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6396 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6397 | } |
| 6398 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6399 | // Test that an HTTP/2 CONNECT through an HTTPS Proxy to a HTTP/2 server and a |
| 6400 | // direct (non-proxied) request to the proxy server are not pooled, as that |
| 6401 | // would break socket pool isolation. |
| 6402 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation1) { |
| 6403 | ProxyConfig proxy_config; |
| 6404 | proxy_config.set_auto_detect(true); |
| 6405 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6406 | |
| 6407 | CapturingProxyResolver capturing_proxy_resolver; |
| 6408 | session_deps_.proxy_resolution_service = |
| 6409 | std::make_unique<ProxyResolutionService>( |
| 6410 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6411 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6412 | std::make_unique<CapturingProxyResolverFactory>( |
| 6413 | &capturing_proxy_resolver), |
| 6414 | nullptr); |
| 6415 | |
| 6416 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6417 | |
| 6418 | SpdyTestUtil spdy_util1; |
| 6419 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6420 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6421 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6422 | HostPortPair("www.example.org", 443))); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6423 | // fetch https://www.example.org/ via HTTP/2. |
| 6424 | const char kMyUrl[] = "https://www.example.org/"; |
| 6425 | spdy::SpdySerializedFrame get(spdy_util1.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6426 | spdy::SpdySerializedFrame wrapped_get( |
| 6427 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6428 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6429 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6430 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6431 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6432 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6433 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6434 | spdy::SpdySerializedFrame body(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6435 | spdy::SpdySerializedFrame wrapped_body( |
| 6436 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6437 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6438 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6439 | spdy::SpdySerializedFrame window_update_body( |
| 6440 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6441 | |
| 6442 | MockWrite spdy_writes1[] = { |
| 6443 | CreateMockWrite(connect, 0), |
| 6444 | CreateMockWrite(wrapped_get, 2), |
| 6445 | CreateMockWrite(window_update_get_resp, 6), |
| 6446 | CreateMockWrite(window_update_body, 7), |
| 6447 | }; |
| 6448 | |
| 6449 | MockRead spdy_reads1[] = { |
| 6450 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6451 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6452 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6453 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6454 | MockRead(ASYNC, 0, 8), |
| 6455 | }; |
| 6456 | |
| 6457 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6458 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6459 | |
| 6460 | // Fetch https://proxy:70/ via HTTP/2. Needs a new SpdyTestUtil, since it uses |
| 6461 | // a new pipe. |
| 6462 | SpdyTestUtil spdy_util2; |
| 6463 | spdy::SpdySerializedFrame req( |
| 6464 | spdy_util2.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6465 | MockWrite spdy_writes2[] = {CreateMockWrite(req, 0)}; |
| 6466 | |
| 6467 | spdy::SpdySerializedFrame resp( |
| 6468 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6469 | spdy::SpdySerializedFrame data(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6470 | MockRead spdy_reads2[] = { |
| 6471 | CreateMockRead(resp, 1), |
| 6472 | CreateMockRead(data, 2), |
| 6473 | MockRead(ASYNC, 0, 3), |
| 6474 | }; |
| 6475 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6476 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6477 | |
| 6478 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6479 | ssl.next_proto = kProtoHTTP2; |
| 6480 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6481 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6482 | ssl2.next_proto = kProtoHTTP2; |
| 6483 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6484 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6485 | ssl3.next_proto = kProtoHTTP2; |
| 6486 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6487 | |
| 6488 | TestCompletionCallback callback; |
| 6489 | std::string response_data; |
| 6490 | |
| 6491 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6492 | capturing_proxy_resolver.set_proxy_server( |
| 6493 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6494 | HttpRequestInfo request1; |
| 6495 | request1.method = "GET"; |
| 6496 | request1.url = GURL("https://www.example.org/"); |
| 6497 | request1.traffic_annotation = |
| 6498 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6499 | |
| 6500 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6501 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 6502 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6503 | |
| 6504 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6505 | base::RunLoop().RunUntilIdle(); |
| 6506 | // Now allow the read of the response to complete. |
| 6507 | spdy_data1.Resume(); |
| 6508 | rv = callback.WaitForResult(); |
| 6509 | EXPECT_THAT(rv, IsOk()); |
| 6510 | |
| 6511 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 6512 | ASSERT_TRUE(response); |
| 6513 | ASSERT_TRUE(response->headers); |
| 6514 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6515 | |
| 6516 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6517 | EXPECT_EQ(kUploadData, response_data); |
| 6518 | RunUntilIdle(); |
| 6519 | |
| 6520 | // Make a direct HTTP/2 request to proxy:70. |
| 6521 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6522 | HttpRequestInfo request2; |
| 6523 | request2.method = "GET"; |
| 6524 | request2.url = GURL("https://proxy:70/"); |
| 6525 | request2.traffic_annotation = |
| 6526 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6527 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6528 | EXPECT_THAT(callback.GetResult(trans2.Start(&request2, callback.callback(), |
| 6529 | NetLogWithSource())), |
| 6530 | IsOk()); |
| 6531 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6532 | } |
| 6533 | |
| 6534 | // Same as above, but reverse request order, since the code to check for an |
| 6535 | // existing session is different for tunnels and direct connections. |
| 6536 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation2) { |
| 6537 | // Configure against https proxy server "myproxy:80". |
| 6538 | ProxyConfig proxy_config; |
| 6539 | proxy_config.set_auto_detect(true); |
| 6540 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6541 | |
| 6542 | CapturingProxyResolver capturing_proxy_resolver; |
| 6543 | session_deps_.proxy_resolution_service = |
| 6544 | std::make_unique<ProxyResolutionService>( |
| 6545 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6546 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6547 | std::make_unique<CapturingProxyResolverFactory>( |
| 6548 | &capturing_proxy_resolver), |
| 6549 | nullptr); |
| 6550 | |
| 6551 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6552 | // Fetch https://proxy:70/ via HTTP/2. |
| 6553 | SpdyTestUtil spdy_util1; |
| 6554 | spdy::SpdySerializedFrame req( |
| 6555 | spdy_util1.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6556 | MockWrite spdy_writes1[] = {CreateMockWrite(req, 0)}; |
| 6557 | |
| 6558 | spdy::SpdySerializedFrame resp( |
| 6559 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6560 | spdy::SpdySerializedFrame data(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6561 | MockRead spdy_reads1[] = { |
| 6562 | CreateMockRead(resp, 1), |
| 6563 | CreateMockRead(data, 2), |
| 6564 | MockRead(ASYNC, 0, 3), |
| 6565 | }; |
| 6566 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6567 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6568 | |
| 6569 | SpdyTestUtil spdy_util2; |
| 6570 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6571 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6572 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6573 | HostPortPair("www.example.org", 443))); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6574 | // fetch https://www.example.org/ via HTTP/2. |
| 6575 | const char kMyUrl[] = "https://www.example.org/"; |
| 6576 | spdy::SpdySerializedFrame get(spdy_util2.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6577 | spdy::SpdySerializedFrame wrapped_get( |
| 6578 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6579 | spdy::SpdySerializedFrame conn_resp( |
| 6580 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6581 | spdy::SpdySerializedFrame get_resp( |
| 6582 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6583 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6584 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6585 | spdy::SpdySerializedFrame body(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6586 | spdy::SpdySerializedFrame wrapped_body( |
| 6587 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6588 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6589 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6590 | spdy::SpdySerializedFrame window_update_body( |
| 6591 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6592 | |
| 6593 | MockWrite spdy_writes2[] = { |
| 6594 | CreateMockWrite(connect, 0), |
| 6595 | CreateMockWrite(wrapped_get, 2), |
| 6596 | CreateMockWrite(window_update_get_resp, 6), |
| 6597 | CreateMockWrite(window_update_body, 7), |
| 6598 | }; |
| 6599 | |
| 6600 | MockRead spdy_reads2[] = { |
| 6601 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6602 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6603 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6604 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6605 | MockRead(ASYNC, 0, 8), |
| 6606 | }; |
| 6607 | |
| 6608 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6609 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6610 | |
| 6611 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6612 | ssl.next_proto = kProtoHTTP2; |
| 6613 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6614 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6615 | ssl2.next_proto = kProtoHTTP2; |
| 6616 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6617 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6618 | ssl3.next_proto = kProtoHTTP2; |
| 6619 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6620 | |
| 6621 | TestCompletionCallback callback; |
| 6622 | std::string response_data; |
| 6623 | |
| 6624 | // Make a direct HTTP/2 request to proxy:70. |
| 6625 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6626 | HttpRequestInfo request1; |
| 6627 | request1.method = "GET"; |
| 6628 | request1.url = GURL("https://proxy:70/"); |
| 6629 | request1.traffic_annotation = |
| 6630 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6631 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6632 | EXPECT_THAT(callback.GetResult(trans1.Start(&request1, callback.callback(), |
| 6633 | NetLogWithSource())), |
| 6634 | IsOk()); |
| 6635 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6636 | RunUntilIdle(); |
| 6637 | |
| 6638 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6639 | capturing_proxy_resolver.set_proxy_server( |
| 6640 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6641 | HttpRequestInfo request2; |
| 6642 | request2.method = "GET"; |
| 6643 | request2.url = GURL("https://www.example.org/"); |
| 6644 | request2.traffic_annotation = |
| 6645 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6646 | |
| 6647 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6648 | int rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 6649 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6650 | |
| 6651 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6652 | base::RunLoop().RunUntilIdle(); |
| 6653 | // Now allow the read of the response to complete. |
| 6654 | spdy_data2.Resume(); |
| 6655 | rv = callback.WaitForResult(); |
| 6656 | EXPECT_THAT(rv, IsOk()); |
| 6657 | |
| 6658 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 6659 | ASSERT_TRUE(response2); |
| 6660 | ASSERT_TRUE(response2->headers); |
| 6661 | EXPECT_EQ("HTTP/1.1 200", response2->headers->GetStatusLine()); |
| 6662 | |
| 6663 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6664 | EXPECT_EQ(kUploadData, response_data); |
| 6665 | } |
| 6666 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6667 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6668 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6669 | HttpRequestInfo request; |
| 6670 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6671 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6672 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 6673 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6674 | request.traffic_annotation = |
| 6675 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6676 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6677 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6678 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6679 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6680 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6681 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6682 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6683 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6684 | // Since we have proxy, should use full url |
| 6685 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6686 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6687 | "Host: www.example.org\r\n" |
| 6688 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6689 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6690 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6691 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6692 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6693 | "Host: www.example.org\r\n" |
| 6694 | "Proxy-Connection: keep-alive\r\n" |
| 6695 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6696 | }; |
| 6697 | |
| 6698 | // The proxy responds to the GET with a 407, using a persistent |
| 6699 | // connection. |
| 6700 | MockRead data_reads1[] = { |
| 6701 | // No credentials. |
| 6702 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 6703 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6704 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 6705 | MockRead("Content-Length: 0\r\n\r\n"), |
| 6706 | |
| 6707 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6708 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6709 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6710 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6711 | }; |
| 6712 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6713 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6714 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6715 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6716 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6717 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6718 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6719 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6720 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6721 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6722 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6723 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6724 | |
| 6725 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6726 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6727 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6728 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6729 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6730 | TestLoadTimingNotReused(load_timing_info, |
| 6731 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6732 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6733 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6734 | ASSERT_TRUE(response); |
| 6735 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6736 | EXPECT_EQ(407, response->headers->response_code()); |
| 6737 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 6738 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6739 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6740 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6741 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6742 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6743 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6744 | |
| 6745 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6746 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6747 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6748 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6749 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6750 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 6751 | TestLoadTimingReused(load_timing_info); |
| 6752 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6753 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6754 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6755 | |
| 6756 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6757 | EXPECT_EQ(200, response->headers->response_code()); |
| 6758 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6759 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6760 | |
| 6761 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6762 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6763 | } |
| 6764 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6765 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6766 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6767 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6768 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6769 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6770 | request.traffic_annotation = |
| 6771 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6772 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6773 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6774 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6775 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6776 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6777 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6778 | // Since we have proxy, should try to establish tunnel. |
| 6779 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6780 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6781 | "Host: www.example.org:443\r\n" |
| 6782 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6783 | }; |
| 6784 | |
| 6785 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6786 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 6787 | // No response body because the test stops reading here. |
| 6788 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6789 | }; |
| 6790 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6791 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6792 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6793 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6794 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6795 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6796 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6797 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6798 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6799 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6800 | |
| 6801 | rv = callback.WaitForResult(); |
| 6802 | EXPECT_EQ(expected_status, rv); |
| 6803 | } |
| 6804 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6805 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 6806 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6807 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6808 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6809 | } |
| 6810 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6811 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6812 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 6813 | } |
| 6814 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6815 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6816 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 6817 | } |
| 6818 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6819 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6820 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 6821 | } |
| 6822 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6823 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6824 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 6825 | } |
| 6826 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6827 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6828 | ConnectStatusHelper( |
| 6829 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 6830 | } |
| 6831 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6832 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6833 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 6834 | } |
| 6835 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6836 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6837 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 6838 | } |
| 6839 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6840 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6841 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 6842 | } |
| 6843 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6844 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6845 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 6846 | } |
| 6847 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6848 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6849 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 6850 | } |
| 6851 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6852 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6853 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 6854 | } |
| 6855 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6856 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6857 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 6858 | } |
| 6859 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6860 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6861 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 6862 | } |
| 6863 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6864 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6865 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 6866 | } |
| 6867 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6868 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6869 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 6870 | } |
| 6871 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6872 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6873 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 6874 | } |
| 6875 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6876 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 6877 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 6878 | } |
| 6879 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6880 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6881 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 6882 | } |
| 6883 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6884 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6885 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 6886 | } |
| 6887 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6888 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6889 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 6890 | } |
| 6891 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6892 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6893 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 6894 | } |
| 6895 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6896 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6897 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 6898 | } |
| 6899 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6900 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6901 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 6902 | } |
| 6903 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6904 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6905 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 6906 | } |
| 6907 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6908 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6909 | ConnectStatusHelperWithExpectedStatus( |
| 6910 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 6911 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6912 | } |
| 6913 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6914 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6915 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 6916 | } |
| 6917 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6918 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6919 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 6920 | } |
| 6921 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6922 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6923 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 6924 | } |
| 6925 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6926 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6927 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 6928 | } |
| 6929 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6930 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6931 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 6932 | } |
| 6933 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6934 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6935 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 6936 | } |
| 6937 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6938 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6939 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 6940 | } |
| 6941 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6942 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6943 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 6944 | } |
| 6945 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6946 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6947 | ConnectStatusHelper( |
| 6948 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 6949 | } |
| 6950 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6951 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6952 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 6953 | } |
| 6954 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6955 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6956 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 6957 | } |
| 6958 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6959 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6960 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 6961 | } |
| 6962 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6963 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6964 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 6965 | } |
| 6966 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6967 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6968 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 6969 | } |
| 6970 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6971 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6972 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 6973 | } |
| 6974 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6975 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6976 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 6977 | } |
| 6978 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6979 | // Test the flow when both the proxy server AND origin server require |
| 6980 | // authentication. Again, this uses basic auth for both since that is |
| 6981 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6982 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6983 | HttpRequestInfo request; |
| 6984 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6985 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6986 | request.traffic_annotation = |
| 6987 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6988 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6989 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6990 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6991 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6992 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6993 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6994 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6995 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6996 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6997 | MockWrite( |
| 6998 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6999 | "Host: www.example.org\r\n" |
| 7000 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7001 | }; |
| 7002 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7003 | MockRead data_reads1[] = { |
| 7004 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 7005 | // Give a couple authenticate options (only the middle one is actually |
| 7006 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 7007 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7008 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7009 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 7010 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7011 | // Large content-length -- won't matter, as connection will be reset. |
| 7012 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7013 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7014 | }; |
| 7015 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7016 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7017 | // request we should be issuing -- the final header line contains the |
| 7018 | // proxy's credentials. |
| 7019 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7020 | MockWrite( |
| 7021 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7022 | "Host: www.example.org\r\n" |
| 7023 | "Proxy-Connection: keep-alive\r\n" |
| 7024 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7025 | }; |
| 7026 | |
| 7027 | // Now the proxy server lets the request pass through to origin server. |
| 7028 | // The origin server responds with a 401. |
| 7029 | MockRead data_reads2[] = { |
| 7030 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7031 | // Note: We are using the same realm-name as the proxy server. This is |
| 7032 | // completely valid, as realms are unique across hosts. |
| 7033 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7034 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7035 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7036 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7037 | }; |
| 7038 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7039 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7040 | // the credentials for both the proxy and origin server. |
| 7041 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7042 | MockWrite( |
| 7043 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7044 | "Host: www.example.org\r\n" |
| 7045 | "Proxy-Connection: keep-alive\r\n" |
| 7046 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 7047 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7048 | }; |
| 7049 | |
| 7050 | // Lastly we get the desired content. |
| 7051 | MockRead data_reads3[] = { |
| 7052 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7053 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7054 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7055 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7056 | }; |
| 7057 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7058 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7059 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7060 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7061 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7062 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7063 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7064 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7065 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7066 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7067 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7068 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7069 | |
| 7070 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7071 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7072 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7073 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7074 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7075 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7076 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7077 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7078 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7079 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7080 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7081 | |
| 7082 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7083 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7084 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7085 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7086 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7087 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7088 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7089 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7090 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7091 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7092 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7093 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7094 | |
| 7095 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7096 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7097 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7098 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7099 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7100 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7101 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7102 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7103 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 7104 | // can't hook into its internals to cause it to generate predictable NTLM |
| 7105 | // authorization headers. |
| 7106 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7107 | // The NTLM authentication unit tests are based on known test data from the |
| 7108 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 7109 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 7110 | // for the implementation and testing of the protocol. |
| 7111 | // |
| 7112 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7113 | |
| 7114 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7115 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7116 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7117 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7118 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7119 | request.traffic_annotation = |
| 7120 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7121 | |
| 7122 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7123 | // to other auth schemes. |
| 7124 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7125 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7126 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7127 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7128 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7129 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7130 | // Generate the NTLM messages based on known test data. |
| 7131 | std::string negotiate_msg; |
| 7132 | std::string challenge_msg; |
| 7133 | std::string authenticate_msg; |
| 7134 | base::Base64Encode( |
| 7135 | base::StringPiece( |
| 7136 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7137 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7138 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7139 | base::Base64Encode( |
| 7140 | base::StringPiece( |
| 7141 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7142 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7143 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7144 | base::Base64Encode( |
| 7145 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7146 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7147 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7148 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7149 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7150 | &authenticate_msg); |
| 7151 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7152 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7153 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7154 | "Host: server\r\n" |
| 7155 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7156 | }; |
| 7157 | |
| 7158 | MockRead data_reads1[] = { |
| 7159 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7160 | // Negotiate and NTLM are often requested together. However, we only want |
| 7161 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7162 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7163 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7164 | MockRead("Connection: close\r\n"), |
| 7165 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7166 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7167 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7168 | }; |
| 7169 | |
| 7170 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7171 | // After restarting with a null identity, this is the |
| 7172 | // request we should be issuing -- the final header line contains a Type |
| 7173 | // 1 message. |
| 7174 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7175 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7176 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7177 | "Authorization: NTLM "), |
| 7178 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7179 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7180 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7181 | // (using correct credentials). The second request continues on the |
| 7182 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7183 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7184 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7185 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7186 | "Authorization: NTLM "), |
| 7187 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7188 | }; |
| 7189 | |
| 7190 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7191 | // The origin server responds with a Type 2 message. |
| 7192 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7193 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7194 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7195 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7196 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7197 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7198 | // Lastly we get the desired content. |
| 7199 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7200 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7201 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7202 | }; |
| 7203 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7204 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7205 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7206 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7207 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7208 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7209 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7210 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7211 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7212 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7213 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7214 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7215 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7216 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7217 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7218 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7219 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7220 | |
| 7221 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7222 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7223 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7224 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7225 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7226 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7227 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7228 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7229 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7230 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7231 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7232 | rv = trans.RestartWithAuth( |
| 7233 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7234 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7235 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7236 | |
| 7237 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7238 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7239 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7240 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7241 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7242 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7243 | ASSERT_TRUE(response); |
| 7244 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7245 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7246 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7247 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7248 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7249 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7250 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7251 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7252 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7253 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7254 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7255 | ASSERT_TRUE(response); |
| 7256 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7257 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7258 | |
| 7259 | std::string response_data; |
| 7260 | rv = ReadTransaction(&trans, &response_data); |
| 7261 | EXPECT_THAT(rv, IsOk()); |
| 7262 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7263 | |
| 7264 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7265 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7266 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7267 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7268 | } |
| 7269 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7270 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7271 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7272 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7273 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7274 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7275 | request.traffic_annotation = |
| 7276 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7277 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7278 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7279 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7280 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7281 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7282 | // Generate the NTLM messages based on known test data. |
| 7283 | std::string negotiate_msg; |
| 7284 | std::string challenge_msg; |
| 7285 | std::string authenticate_msg; |
| 7286 | base::Base64Encode( |
| 7287 | base::StringPiece( |
| 7288 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7289 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7290 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7291 | base::Base64Encode( |
| 7292 | base::StringPiece( |
| 7293 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7294 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7295 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7296 | base::Base64Encode( |
| 7297 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7298 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7299 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7300 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7301 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7302 | &authenticate_msg); |
| 7303 | |
| 7304 | // The authenticate message when |kWrongPassword| is sent. |
| 7305 | std::string wrong_password_authenticate_msg( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7306 | "TlRMTVNTUAADAAAAGAAYAFgAAACKAIoAcAAAAAwADAD6AAAACAAIAAYBAAAQABAADgEAAAAA" |
| 7307 | "AABYAAAAA4IIAAAAAAAAAAAAAPknEYqtJQtusopDRSfYzAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 7308 | "AAAAAOtVz38osnFdRRggUQHUJ3EBAQAAAAAAAIALyP0A1NIBqqqqqqqqqqoAAAAAAgAMAEQA" |
| 7309 | "bwBtAGEAaQBuAAEADABTAGUAcgB2AGUAcgAGAAQAAgAAAAoAEAAAAAAAAAAAAAAAAAAAAAAA" |
| 7310 | "CQAWAEgAVABUAFAALwBzAGUAcgB2AGUAcgAAAAAAAAAAAEQAbwBtAGEAaQBuAFUAcwBlAHIA" |
| 7311 | "QwBPAE0AUABVAFQARQBSAA=="); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7312 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7313 | // Sanity check that it's the same length as the correct authenticate message |
| 7314 | // and that it's different. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7315 | ASSERT_EQ(authenticate_msg.length(), |
| 7316 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7317 | ASSERT_NE(authenticate_msg, wrong_password_authenticate_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7318 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7319 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7320 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7321 | "Host: server\r\n" |
| 7322 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7323 | }; |
| 7324 | |
| 7325 | MockRead data_reads1[] = { |
| 7326 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7327 | // Negotiate and NTLM are often requested together. However, we only want |
| 7328 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7329 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7330 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7331 | MockRead("Connection: close\r\n"), |
| 7332 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7333 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7334 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7335 | }; |
| 7336 | |
| 7337 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7338 | // After restarting with a null identity, this is the |
| 7339 | // request we should be issuing -- the final header line contains a Type |
| 7340 | // 1 message. |
| 7341 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7342 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7343 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7344 | "Authorization: NTLM "), |
| 7345 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7346 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7347 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7348 | // (using incorrect credentials). The second request continues on the |
| 7349 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7350 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7351 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7352 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7353 | "Authorization: NTLM "), |
| 7354 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7355 | }; |
| 7356 | |
| 7357 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7358 | // The origin server responds with a Type 2 message. |
| 7359 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7360 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7361 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 7362 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7363 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7364 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7365 | // Wrong password. |
| 7366 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7367 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 7368 | MockRead("Content-Length: 42\r\n"), |
| 7369 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7370 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7371 | }; |
| 7372 | |
| 7373 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7374 | // After restarting with a null identity, this is the |
| 7375 | // request we should be issuing -- the final header line contains a Type |
| 7376 | // 1 message. |
| 7377 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7378 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7379 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7380 | "Authorization: NTLM "), |
| 7381 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7382 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7383 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7384 | // (the credentials for the origin server). The second request continues |
| 7385 | // on the same connection. |
| 7386 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7387 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7388 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7389 | "Authorization: NTLM "), |
| 7390 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7391 | }; |
| 7392 | |
| 7393 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7394 | // The origin server responds with a Type 2 message. |
| 7395 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7396 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7397 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7398 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7399 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7400 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7401 | // Lastly we get the desired content. |
| 7402 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7403 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7404 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7405 | }; |
| 7406 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7407 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7408 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7409 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7410 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7411 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7412 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7413 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7414 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7415 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7416 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7417 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7418 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 7419 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 7420 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7421 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7422 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7423 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7424 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7425 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7426 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7427 | |
| 7428 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7429 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7430 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7431 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7432 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7433 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7434 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7435 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7436 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7437 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7438 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7439 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7440 | rv = trans.RestartWithAuth( |
| 7441 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 7442 | callback2.callback()); |
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 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7445 | rv = callback2.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_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7449 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7450 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7451 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7452 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7453 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7454 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7455 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7456 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7457 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7458 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7459 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7460 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7461 | |
| 7462 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7463 | rv = trans.RestartWithAuth( |
| 7464 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7465 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7466 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7467 | |
| 7468 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7469 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7470 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7471 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7472 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7473 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7474 | |
| 7475 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7476 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7477 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7478 | |
| 7479 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7480 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7481 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7482 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7483 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7484 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7485 | |
| 7486 | std::string response_data; |
| 7487 | rv = ReadTransaction(&trans, &response_data); |
| 7488 | EXPECT_THAT(rv, IsOk()); |
| 7489 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7490 | |
| 7491 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7492 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7493 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7494 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 7495 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 7496 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7497 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7498 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7499 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 7500 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7501 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7502 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7503 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7504 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7505 | const char* kUrl = "https://server/kids/login.aspx"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7506 | |
| 7507 | HttpRequestInfo request; |
| 7508 | request.method = "GET"; |
| 7509 | request.url = GURL(kUrl); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7510 | request.traffic_annotation = |
| 7511 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7512 | |
| 7513 | // First request without credentials. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7514 | spdy::SpdyHeaderBlock request_headers0( |
| 7515 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 7516 | spdy::SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7517 | 1, std::move(request_headers0), LOWEST, true)); |
| 7518 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7519 | spdy::SpdyHeaderBlock response_headers0; |
| 7520 | response_headers0[spdy::kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7521 | response_headers0["www-authenticate"] = "NTLM"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7522 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7523 | 1, std::move(response_headers0), true)); |
| 7524 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7525 | // Stream 1 is closed. |
| 7526 | spdy_util_.UpdateWithStreamDestruction(1); |
| 7527 | |
| 7528 | // Generate the NTLM messages based on known test data. |
| 7529 | std::string negotiate_msg; |
| 7530 | std::string challenge_msg; |
| 7531 | std::string authenticate_msg; |
| 7532 | base::Base64Encode( |
| 7533 | base::StringPiece( |
| 7534 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7535 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7536 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7537 | base::Base64Encode( |
| 7538 | base::StringPiece( |
| 7539 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7540 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7541 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7542 | base::Base64Encode( |
| 7543 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7544 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7545 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7546 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7547 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7548 | &authenticate_msg); |
| 7549 | |
| 7550 | // Retry with authorization header. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7551 | spdy::SpdyHeaderBlock request_headers1( |
| 7552 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7553 | request_headers1["authorization"] = std::string("NTLM ") + negotiate_msg; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7554 | spdy::SpdySerializedFrame request1(spdy_util_.ConstructSpdyHeaders( |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7555 | 3, std::move(request_headers1), LOWEST, true)); |
| 7556 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7557 | spdy::SpdySerializedFrame rst( |
| 7558 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_HTTP_1_1_REQUIRED)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7559 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7560 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
| 7561 | MockRead reads0[] = {CreateMockRead(resp, 1), MockRead(ASYNC, 0, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7562 | |
| 7563 | // Retry yet again using HTTP/1.1. |
| 7564 | MockWrite writes1[] = { |
| 7565 | // After restarting with a null identity, this is the |
| 7566 | // request we should be issuing -- the final header line contains a Type |
| 7567 | // 1 message. |
| 7568 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7569 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7570 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7571 | "Authorization: NTLM "), |
| 7572 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7573 | |
| 7574 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7575 | // (the credentials for the origin server). The second request continues |
| 7576 | // on the same connection. |
| 7577 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7578 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7579 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7580 | "Authorization: NTLM "), |
| 7581 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7582 | }; |
| 7583 | |
| 7584 | MockRead reads1[] = { |
| 7585 | // The origin server responds with a Type 2 message. |
| 7586 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7587 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7588 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7589 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7590 | MockRead("You are not authorized to view this page\r\n"), |
| 7591 | |
| 7592 | // Lastly we get the desired content. |
| 7593 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7594 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7595 | 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] | 7596 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7597 | SequencedSocketData data0(reads0, writes0); |
| 7598 | StaticSocketDataProvider data1(reads1, writes1); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7599 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 7600 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7601 | |
| 7602 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 7603 | ssl0.next_proto = kProtoHTTP2; |
| 7604 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7605 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 7606 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7607 | |
| 7608 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7609 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7610 | |
| 7611 | TestCompletionCallback callback1; |
| 7612 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 7613 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7614 | |
| 7615 | rv = callback1.WaitForResult(); |
| 7616 | EXPECT_THAT(rv, IsOk()); |
| 7617 | |
| 7618 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7619 | |
| 7620 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7621 | ASSERT_TRUE(response); |
| 7622 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
| 7623 | |
| 7624 | TestCompletionCallback callback2; |
| 7625 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7626 | rv = trans.RestartWithAuth( |
| 7627 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7628 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7629 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7630 | |
| 7631 | rv = callback2.WaitForResult(); |
| 7632 | EXPECT_THAT(rv, IsOk()); |
| 7633 | |
| 7634 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7635 | |
| 7636 | response = trans.GetResponseInfo(); |
| 7637 | ASSERT_TRUE(response); |
| 7638 | EXPECT_FALSE(response->auth_challenge); |
| 7639 | |
| 7640 | TestCompletionCallback callback3; |
| 7641 | |
| 7642 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 7643 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7644 | |
| 7645 | rv = callback3.WaitForResult(); |
| 7646 | EXPECT_THAT(rv, IsOk()); |
| 7647 | |
| 7648 | response = trans.GetResponseInfo(); |
| 7649 | ASSERT_TRUE(response); |
| 7650 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7651 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7652 | |
| 7653 | std::string response_data; |
| 7654 | rv = ReadTransaction(&trans, &response_data); |
| 7655 | EXPECT_THAT(rv, IsOk()); |
| 7656 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7657 | |
| 7658 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 7659 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 7660 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7661 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7662 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7663 | |
| 7664 | // Test that, if we have an NTLM proxy and the origin resets the connection, we |
| 7665 | // do no retry forever checking for TLS version interference. This is a |
| 7666 | // regression test for https://crbug.com/823387. |
| 7667 | TEST_F(HttpNetworkTransactionTest, NTLMProxyTLSHandshakeReset) { |
| 7668 | // The NTLM test data expects the proxy to be named 'server'. The origin is |
| 7669 | // https://origin/. |
| 7670 | session_deps_.proxy_resolution_service = |
| 7671 | ProxyResolutionService::CreateFixedFromPacResult( |
| 7672 | "PROXY server", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7673 | |
| 7674 | SSLConfig config; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7675 | session_deps_.ssl_config_service = |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 7676 | std::make_unique<TestSSLConfigService>(config); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7677 | |
| 7678 | HttpRequestInfo request; |
| 7679 | request.method = "GET"; |
| 7680 | request.url = GURL("https://origin/"); |
| 7681 | request.traffic_annotation = |
| 7682 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7683 | |
| 7684 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7685 | // to other auth schemes. |
| 7686 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 7687 | |
| 7688 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7689 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
| 7690 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7691 | |
| 7692 | // Generate the NTLM messages based on known test data. |
| 7693 | std::string negotiate_msg; |
| 7694 | std::string challenge_msg; |
| 7695 | std::string authenticate_msg; |
| 7696 | base::Base64Encode( |
| 7697 | base::StringPiece( |
| 7698 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7699 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7700 | &negotiate_msg); |
| 7701 | base::Base64Encode( |
| 7702 | base::StringPiece( |
| 7703 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7704 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7705 | &challenge_msg); |
| 7706 | base::Base64Encode( |
| 7707 | base::StringPiece( |
| 7708 | reinterpret_cast<const char*>( |
| 7709 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7710 | base::size( |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7711 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
| 7712 | &authenticate_msg); |
| 7713 | |
| 7714 | MockWrite data_writes[] = { |
| 7715 | // The initial CONNECT request. |
| 7716 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7717 | "Host: origin:443\r\n" |
| 7718 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7719 | |
| 7720 | // After restarting with an identity. |
| 7721 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7722 | "Host: origin:443\r\n" |
| 7723 | "Proxy-Connection: keep-alive\r\n" |
| 7724 | "Proxy-Authorization: NTLM "), |
| 7725 | MockWrite(negotiate_msg.c_str()), |
| 7726 | // End headers. |
| 7727 | MockWrite("\r\n\r\n"), |
| 7728 | |
| 7729 | // The second restart. |
| 7730 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7731 | "Host: origin:443\r\n" |
| 7732 | "Proxy-Connection: keep-alive\r\n" |
| 7733 | "Proxy-Authorization: NTLM "), |
| 7734 | MockWrite(authenticate_msg.c_str()), |
| 7735 | // End headers. |
| 7736 | MockWrite("\r\n\r\n"), |
| 7737 | }; |
| 7738 | |
| 7739 | MockRead data_reads[] = { |
| 7740 | // The initial NTLM response. |
| 7741 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 7742 | "Content-Length: 0\r\n" |
| 7743 | "Proxy-Authenticate: NTLM\r\n\r\n"), |
| 7744 | |
| 7745 | // The NTLM challenge message. |
| 7746 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 7747 | "Content-Length: 0\r\n" |
| 7748 | "Proxy-Authenticate: NTLM "), |
| 7749 | MockRead(challenge_msg.c_str()), |
| 7750 | // End headers. |
| 7751 | MockRead("\r\n\r\n"), |
| 7752 | |
| 7753 | // Finally the tunnel is established. |
| 7754 | MockRead("HTTP/1.1 200 Connected\r\n\r\n"), |
| 7755 | }; |
| 7756 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7757 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7758 | SSLSocketDataProvider data_ssl(ASYNC, ERR_CONNECTION_RESET); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7759 | StaticSocketDataProvider data2(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7760 | SSLSocketDataProvider data_ssl2(ASYNC, ERR_CONNECTION_RESET); |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 7761 | data_ssl2.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7762 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7763 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl); |
| 7764 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7765 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl2); |
| 7766 | |
| 7767 | // Start the transaction. The proxy responds with an NTLM authentication |
| 7768 | // request. |
| 7769 | TestCompletionCallback callback; |
| 7770 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7771 | int rv = callback.GetResult( |
| 7772 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 7773 | |
| 7774 | EXPECT_THAT(rv, IsOk()); |
| 7775 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7776 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7777 | ASSERT_TRUE(response); |
| 7778 | EXPECT_TRUE(CheckNTLMProxyAuth(response->auth_challenge.get())); |
| 7779 | |
| 7780 | // Configure credentials. The proxy responds with the challenge message. |
| 7781 | rv = callback.GetResult(trans.RestartWithAuth( |
| 7782 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7783 | callback.callback())); |
| 7784 | EXPECT_THAT(rv, IsOk()); |
| 7785 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7786 | response = trans.GetResponseInfo(); |
| 7787 | ASSERT_TRUE(response); |
| 7788 | EXPECT_FALSE(response->auth_challenge); |
| 7789 | |
| 7790 | // Restart once more. The tunnel will be established and the the SSL handshake |
| 7791 | // will reset. The TLS 1.3 version interference probe will then kick in and |
| 7792 | // restart the process. The proxy responds with another NTLM authentiation |
| 7793 | // request, but we don't need to provide credentials as the cached ones work/ |
| 7794 | rv = callback.GetResult( |
| 7795 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7796 | EXPECT_THAT(rv, IsOk()); |
| 7797 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7798 | response = trans.GetResponseInfo(); |
| 7799 | ASSERT_TRUE(response); |
| 7800 | EXPECT_FALSE(response->auth_challenge); |
| 7801 | |
| 7802 | // The proxy responds with the NTLM challenge message. |
| 7803 | rv = callback.GetResult( |
| 7804 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7805 | EXPECT_THAT(rv, IsOk()); |
| 7806 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7807 | response = trans.GetResponseInfo(); |
| 7808 | ASSERT_TRUE(response); |
| 7809 | EXPECT_FALSE(response->auth_challenge); |
| 7810 | |
| 7811 | // Send the NTLM authenticate message. The tunnel is established and the |
| 7812 | // handshake resets again. We should not retry again. |
| 7813 | rv = callback.GetResult( |
| 7814 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7815 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
| 7816 | } |
| 7817 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7818 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7819 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7820 | // Test reading a server response which has only headers, and no body. |
| 7821 | // After some maximum number of bytes is consumed, the transaction should |
| 7822 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7823 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7824 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7825 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7826 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7827 | request.traffic_annotation = |
| 7828 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7829 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7830 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7831 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7832 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7833 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 7834 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7835 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7836 | |
| 7837 | MockRead data_reads[] = { |
| 7838 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7839 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7840 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7841 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7842 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7843 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7844 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7845 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7846 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7847 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7848 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7849 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7850 | |
| 7851 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7852 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7853 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7854 | |
| 7855 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 7856 | // establish tunnel. |
| 7857 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7858 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7859 | HttpRequestInfo request; |
| 7860 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7861 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7862 | request.traffic_annotation = |
| 7863 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7864 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7865 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 7866 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 7867 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 7868 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7869 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7870 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7871 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7872 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7873 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7874 | // Since we have proxy, should try to establish tunnel. |
| 7875 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7876 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7877 | "Host: www.example.org:443\r\n" |
| 7878 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7879 | }; |
| 7880 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7881 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7882 | // connection. Usually a proxy would return 501 (not implemented), |
| 7883 | // or 200 (tunnel established). |
| 7884 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 7885 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7886 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7887 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7888 | }; |
| 7889 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7890 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7891 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7892 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7893 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7894 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7895 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7896 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7897 | |
| 7898 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7899 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7900 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7901 | // Empty the current queue. This is necessary because idle sockets are |
| 7902 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7903 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7904 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7905 | // We now check to make sure the TCPClientSocket was not added back to |
| 7906 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7907 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7908 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7909 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7910 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7911 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7912 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7913 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7914 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7915 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7916 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7917 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7918 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7919 | request.traffic_annotation = |
| 7920 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7921 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7922 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7923 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7924 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7925 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7926 | MockRead data_reads[] = { |
| 7927 | // A part of the response body is received with the response headers. |
| 7928 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7929 | // The rest of the response body is received in two parts. |
| 7930 | MockRead("lo"), |
| 7931 | MockRead(" world"), |
| 7932 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7933 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7934 | }; |
| 7935 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7936 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7937 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7938 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7939 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7940 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7941 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7942 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7943 | |
| 7944 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7945 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7946 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7947 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7948 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7949 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7950 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7951 | std::string status_line = response->headers->GetStatusLine(); |
| 7952 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7953 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7954 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7955 | |
| 7956 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7957 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7958 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7959 | EXPECT_EQ("hello world", response_data); |
| 7960 | |
| 7961 | // Empty the current queue. This is necessary because idle sockets are |
| 7962 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7963 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7964 | |
| 7965 | // 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] | 7966 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7967 | } |
| 7968 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7969 | // Make sure that we recycle a SSL socket after reading all of the response |
| 7970 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7971 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7972 | HttpRequestInfo request; |
| 7973 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7974 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7975 | request.traffic_annotation = |
| 7976 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7977 | |
| 7978 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7979 | MockWrite( |
| 7980 | "GET / HTTP/1.1\r\n" |
| 7981 | "Host: www.example.org\r\n" |
| 7982 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7983 | }; |
| 7984 | |
| 7985 | MockRead data_reads[] = { |
| 7986 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7987 | MockRead("Content-Length: 11\r\n\r\n"), |
| 7988 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7989 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7990 | }; |
| 7991 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7992 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7993 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7994 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7995 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7996 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7997 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7998 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7999 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8000 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8001 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8002 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8003 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8004 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8005 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8006 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8007 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8008 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8009 | ASSERT_TRUE(response); |
| 8010 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8011 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8012 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8013 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8014 | |
| 8015 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8016 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8017 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8018 | EXPECT_EQ("hello world", response_data); |
| 8019 | |
| 8020 | // Empty the current queue. This is necessary because idle sockets are |
| 8021 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8022 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8023 | |
| 8024 | // 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] | 8025 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8026 | } |
| 8027 | |
| 8028 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 8029 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8030 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8031 | HttpRequestInfo request; |
| 8032 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8033 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8034 | request.traffic_annotation = |
| 8035 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8036 | |
| 8037 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8038 | MockWrite( |
| 8039 | "GET / HTTP/1.1\r\n" |
| 8040 | "Host: www.example.org\r\n" |
| 8041 | "Connection: keep-alive\r\n\r\n"), |
| 8042 | MockWrite( |
| 8043 | "GET / HTTP/1.1\r\n" |
| 8044 | "Host: www.example.org\r\n" |
| 8045 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8046 | }; |
| 8047 | |
| 8048 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 8049 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8050 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8051 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8052 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8053 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8054 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8055 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8056 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8057 | StaticSocketDataProvider data(data_reads, data_writes); |
| 8058 | StaticSocketDataProvider data2(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8059 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8060 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8061 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8062 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8063 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8064 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8065 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8066 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8067 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8068 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8069 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8070 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8071 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8072 | |
| 8073 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8074 | ASSERT_TRUE(response); |
| 8075 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8076 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8077 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8078 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8079 | |
| 8080 | std::string response_data; |
| 8081 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8082 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8083 | EXPECT_EQ("hello world", response_data); |
| 8084 | |
| 8085 | // Empty the current queue. This is necessary because idle sockets are |
| 8086 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8087 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8088 | |
| 8089 | // 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] | 8090 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8091 | |
| 8092 | // Now start the second transaction, which should reuse the previous socket. |
| 8093 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8094 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8095 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8096 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8097 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8098 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8099 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8100 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8101 | |
| 8102 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8103 | ASSERT_TRUE(response); |
| 8104 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8105 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8106 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8107 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8108 | |
| 8109 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8110 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8111 | EXPECT_EQ("hello world", response_data); |
| 8112 | |
| 8113 | // Empty the current queue. This is necessary because idle sockets are |
| 8114 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8115 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8116 | |
| 8117 | // 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] | 8118 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8119 | } |
| 8120 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8121 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8122 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8123 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8124 | HttpRequestInfo request; |
| 8125 | request.method = "GET"; |
| 8126 | request.url = GURL("http://www.example.org/"); |
| 8127 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8128 | request.traffic_annotation = |
| 8129 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8130 | |
| 8131 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8132 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8133 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8134 | |
| 8135 | MockRead data_reads[] = { |
| 8136 | // A part of the response body is received with the response headers. |
| 8137 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8138 | // The rest of the response body is received in two parts. |
| 8139 | MockRead("lo"), MockRead(" world"), |
| 8140 | MockRead("junk"), // Should not be read!! |
| 8141 | MockRead(SYNCHRONOUS, OK), |
| 8142 | }; |
| 8143 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8144 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8145 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8146 | |
| 8147 | TestCompletionCallback callback; |
| 8148 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8149 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8150 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8151 | |
| 8152 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8153 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8154 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8155 | ASSERT_TRUE(response); |
| 8156 | EXPECT_TRUE(response->headers); |
| 8157 | std::string status_line = response->headers->GetStatusLine(); |
| 8158 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8159 | |
| 8160 | // Make memory critical notification and ensure the transaction still has been |
| 8161 | // operating right. |
| 8162 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8163 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8164 | base::RunLoop().RunUntilIdle(); |
| 8165 | |
| 8166 | // Socket should not be flushed as long as it is not idle. |
| 8167 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8168 | |
| 8169 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8170 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8171 | EXPECT_THAT(rv, IsOk()); |
| 8172 | EXPECT_EQ("hello world", response_data); |
| 8173 | |
| 8174 | // Empty the current queue. This is necessary because idle sockets are |
| 8175 | // added to the connection pool asynchronously with a PostTask. |
| 8176 | base::RunLoop().RunUntilIdle(); |
| 8177 | |
| 8178 | // We now check to make sure the socket was added back to the pool. |
| 8179 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8180 | |
| 8181 | // Idle sockets should be flushed now. |
| 8182 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8183 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8184 | base::RunLoop().RunUntilIdle(); |
| 8185 | |
| 8186 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8187 | } |
| 8188 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8189 | // Disable idle socket closing on memory pressure. |
| 8190 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8191 | // low memory notification and ensure the socket pool is NOT flushed. |
| 8192 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 8193 | HttpRequestInfo request; |
| 8194 | request.method = "GET"; |
| 8195 | request.url = GURL("http://www.example.org/"); |
| 8196 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8197 | request.traffic_annotation = |
| 8198 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8199 | |
| 8200 | // Disable idle socket closing on memory pressure. |
| 8201 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 8202 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8203 | |
| 8204 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 8205 | |
| 8206 | MockRead data_reads[] = { |
| 8207 | // A part of the response body is received with the response headers. |
| 8208 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8209 | // The rest of the response body is received in two parts. |
| 8210 | MockRead("lo"), MockRead(" world"), |
| 8211 | MockRead("junk"), // Should not be read!! |
| 8212 | MockRead(SYNCHRONOUS, OK), |
| 8213 | }; |
| 8214 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8215 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8216 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8217 | |
| 8218 | TestCompletionCallback callback; |
| 8219 | |
| 8220 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 8221 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8222 | |
| 8223 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8224 | |
| 8225 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 8226 | ASSERT_TRUE(response); |
| 8227 | EXPECT_TRUE(response->headers); |
| 8228 | std::string status_line = response->headers->GetStatusLine(); |
| 8229 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8230 | |
| 8231 | // Make memory critical notification and ensure the transaction still has been |
| 8232 | // operating right. |
| 8233 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8234 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8235 | base::RunLoop().RunUntilIdle(); |
| 8236 | |
| 8237 | // Socket should not be flushed as long as it is not idle. |
| 8238 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8239 | |
| 8240 | std::string response_data; |
| 8241 | rv = ReadTransaction(&trans, &response_data); |
| 8242 | EXPECT_THAT(rv, IsOk()); |
| 8243 | EXPECT_EQ("hello world", response_data); |
| 8244 | |
| 8245 | // Empty the current queue. This is necessary because idle sockets are |
| 8246 | // added to the connection pool asynchronously with a PostTask. |
| 8247 | base::RunLoop().RunUntilIdle(); |
| 8248 | |
| 8249 | // We now check to make sure the socket was added back to the pool. |
| 8250 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8251 | |
| 8252 | // Idle sockets should NOT be flushed on moderate memory pressure. |
| 8253 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8254 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 8255 | base::RunLoop().RunUntilIdle(); |
| 8256 | |
| 8257 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8258 | |
| 8259 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 8260 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8261 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8262 | base::RunLoop().RunUntilIdle(); |
| 8263 | |
| 8264 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8265 | } |
| 8266 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8267 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 8268 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8269 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8270 | HttpRequestInfo request; |
| 8271 | request.method = "GET"; |
| 8272 | request.url = GURL("https://www.example.org/"); |
| 8273 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8274 | request.traffic_annotation = |
| 8275 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8276 | |
| 8277 | MockWrite data_writes[] = { |
| 8278 | MockWrite("GET / HTTP/1.1\r\n" |
| 8279 | "Host: www.example.org\r\n" |
| 8280 | "Connection: keep-alive\r\n\r\n"), |
| 8281 | }; |
| 8282 | |
| 8283 | MockRead data_reads[] = { |
| 8284 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8285 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 8286 | |
| 8287 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8288 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8289 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8290 | StaticSocketDataProvider data(data_reads, data_writes); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8291 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8292 | |
| 8293 | TestCompletionCallback callback; |
| 8294 | |
| 8295 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8296 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8297 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8298 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8299 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8300 | |
| 8301 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8302 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8303 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8304 | ASSERT_TRUE(response); |
| 8305 | ASSERT_TRUE(response->headers); |
| 8306 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8307 | |
| 8308 | // Make memory critical notification and ensure the transaction still has been |
| 8309 | // operating right. |
| 8310 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8311 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8312 | base::RunLoop().RunUntilIdle(); |
| 8313 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8314 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8315 | |
| 8316 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8317 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8318 | EXPECT_THAT(rv, IsOk()); |
| 8319 | EXPECT_EQ("hello world", response_data); |
| 8320 | |
| 8321 | // Empty the current queue. This is necessary because idle sockets are |
| 8322 | // added to the connection pool asynchronously with a PostTask. |
| 8323 | base::RunLoop().RunUntilIdle(); |
| 8324 | |
| 8325 | // 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] | 8326 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8327 | |
| 8328 | // Make memory notification once again and ensure idle socket is closed. |
| 8329 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8330 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8331 | base::RunLoop().RunUntilIdle(); |
| 8332 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8333 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8334 | } |
| 8335 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8336 | // Make sure that we recycle a socket after a zero-length response. |
| 8337 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8338 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8339 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8340 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8341 | request.url = GURL( |
| 8342 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 8343 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 8344 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 8345 | "rt=prt.2642,ol.2649,xjs.2951"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8346 | request.traffic_annotation = |
| 8347 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8348 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8349 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8350 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8351 | MockRead data_reads[] = { |
| 8352 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 8353 | "Content-Length: 0\r\n" |
| 8354 | "Content-Type: text/html\r\n\r\n"), |
| 8355 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8356 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8357 | }; |
| 8358 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8359 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8360 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8361 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8362 | // Transaction must be created after the MockReads, so it's destroyed before |
| 8363 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8364 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8365 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8366 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8367 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8368 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8369 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8370 | |
| 8371 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8372 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8373 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8374 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8375 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8376 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8377 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8378 | std::string status_line = response->headers->GetStatusLine(); |
| 8379 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 8380 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8381 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8382 | |
| 8383 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8384 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8385 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8386 | EXPECT_EQ("", response_data); |
| 8387 | |
| 8388 | // Empty the current queue. This is necessary because idle sockets are |
| 8389 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8390 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8391 | |
| 8392 | // 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] | 8393 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8394 | } |
| 8395 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8396 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8397 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8398 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8399 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8400 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8401 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8402 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8403 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 8404 | // after use. |
| 8405 | request[0].method = "GET"; |
| 8406 | request[0].url = GURL("http://www.google.com/"); |
| 8407 | request[0].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8408 | request[0].traffic_annotation = |
| 8409 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8410 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 8411 | // transaction 1. The first attempts fails when writing the POST data. |
| 8412 | // This causes the transaction to retry with a new socket. The second |
| 8413 | // attempt succeeds. |
| 8414 | request[1].method = "POST"; |
| 8415 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8416 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8417 | request[1].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8418 | request[1].traffic_annotation = |
| 8419 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8420 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8421 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8422 | |
| 8423 | // The first socket is used for transaction 1 and the first attempt of |
| 8424 | // transaction 2. |
| 8425 | |
| 8426 | // The response of transaction 1. |
| 8427 | MockRead data_reads1[] = { |
| 8428 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 8429 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8430 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8431 | }; |
| 8432 | // The mock write results of transaction 1 and the first attempt of |
| 8433 | // transaction 2. |
| 8434 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8435 | MockWrite(SYNCHRONOUS, 64), // GET |
| 8436 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8437 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8438 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8439 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8440 | |
| 8441 | // The second socket is used for the second attempt of transaction 2. |
| 8442 | |
| 8443 | // The response of transaction 2. |
| 8444 | MockRead data_reads2[] = { |
| 8445 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 8446 | MockRead("welcome"), |
[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 the second attempt of transaction 2. |
| 8450 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8451 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8452 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8453 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8454 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8455 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8456 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8457 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8458 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8459 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8460 | "hello world", "welcome" |
| 8461 | }; |
| 8462 | |
| 8463 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8464 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8465 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8466 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8467 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8468 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8469 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8470 | |
| 8471 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8472 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8473 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8474 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8475 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8476 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8477 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8478 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8479 | |
| 8480 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8481 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8482 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8483 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 8484 | } |
| 8485 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8486 | |
| 8487 | // Test the request-challenge-retry sequence for basic auth when there is |
| 8488 | // 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] | 8489 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8490 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8491 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8492 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8493 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 8494 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8495 | request.traffic_annotation = |
| 8496 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8497 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8498 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8499 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8500 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8501 | // The password contains an escaped character -- for this test to pass it |
| 8502 | // will need to be unescaped by HttpNetworkTransaction. |
| 8503 | EXPECT_EQ("b%40r", request.url.password()); |
| 8504 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8505 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8506 | MockWrite( |
| 8507 | "GET / HTTP/1.1\r\n" |
| 8508 | "Host: www.example.org\r\n" |
| 8509 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8510 | }; |
| 8511 | |
| 8512 | MockRead data_reads1[] = { |
| 8513 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8514 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8515 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8516 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8517 | }; |
| 8518 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8519 | // After the challenge above, the transaction will be restarted using the |
| 8520 | // identity from the url (foo, b@r) to answer the challenge. |
| 8521 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8522 | MockWrite( |
| 8523 | "GET / HTTP/1.1\r\n" |
| 8524 | "Host: www.example.org\r\n" |
| 8525 | "Connection: keep-alive\r\n" |
| 8526 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8527 | }; |
| 8528 | |
| 8529 | MockRead data_reads2[] = { |
| 8530 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8531 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8532 | MockRead(SYNCHRONOUS, OK), |
| 8533 | }; |
| 8534 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8535 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8536 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8537 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8538 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8539 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8540 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8541 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8542 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8543 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8544 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8545 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8546 | |
| 8547 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8548 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8549 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8550 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8551 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8552 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8553 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8554 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8555 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8556 | |
| 8557 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8558 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8559 | |
| 8560 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8561 | |
| 8562 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8563 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8564 | } |
| 8565 | |
| 8566 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 8567 | // incorrect identity in the URL. The identity from the URL should be used only |
| 8568 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8569 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8570 | HttpRequestInfo request; |
| 8571 | request.method = "GET"; |
| 8572 | // Note: the URL has a username:password in it. The password "baz" is |
| 8573 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8574 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8575 | |
| 8576 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8577 | request.traffic_annotation = |
| 8578 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8579 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8580 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8581 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8582 | |
| 8583 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8584 | MockWrite( |
| 8585 | "GET / HTTP/1.1\r\n" |
| 8586 | "Host: www.example.org\r\n" |
| 8587 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8588 | }; |
| 8589 | |
| 8590 | MockRead data_reads1[] = { |
| 8591 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8592 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8593 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8594 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8595 | }; |
| 8596 | |
| 8597 | // After the challenge above, the transaction will be restarted using the |
| 8598 | // identity from the url (foo, baz) to answer the challenge. |
| 8599 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8600 | MockWrite( |
| 8601 | "GET / HTTP/1.1\r\n" |
| 8602 | "Host: www.example.org\r\n" |
| 8603 | "Connection: keep-alive\r\n" |
| 8604 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8605 | }; |
| 8606 | |
| 8607 | MockRead data_reads2[] = { |
| 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 supplied by the user (foo, bar) to answer the challenge. |
| 8616 | MockWrite data_writes3[] = { |
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 Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8622 | }; |
| 8623 | |
| 8624 | MockRead data_reads3[] = { |
| 8625 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8626 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8627 | MockRead(SYNCHRONOUS, OK), |
| 8628 | }; |
| 8629 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8630 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8631 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 8632 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8633 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8634 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8635 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8636 | |
| 8637 | TestCompletionCallback callback1; |
| 8638 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8639 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8640 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8641 | |
| 8642 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8643 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8644 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8645 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8646 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8647 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8648 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8649 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8650 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8651 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8652 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8653 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8654 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8655 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 8656 | |
| 8657 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8658 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8659 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8660 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8661 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8662 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8663 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8664 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8665 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8666 | |
| 8667 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8668 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8669 | |
| 8670 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8671 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8672 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8673 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8674 | } |
| 8675 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8676 | |
| 8677 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 8678 | // correct identity in the URL, but its use is being suppressed. The identity |
| 8679 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8680 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8681 | HttpRequestInfo request; |
| 8682 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8683 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8684 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8685 | request.traffic_annotation = |
| 8686 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8687 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8688 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8689 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8690 | |
| 8691 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8692 | MockWrite( |
| 8693 | "GET / HTTP/1.1\r\n" |
| 8694 | "Host: www.example.org\r\n" |
| 8695 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8696 | }; |
| 8697 | |
| 8698 | MockRead data_reads1[] = { |
| 8699 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8700 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8701 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8702 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8703 | }; |
| 8704 | |
| 8705 | // After the challenge above, the transaction will be restarted using the |
| 8706 | // identity supplied by the user, not the one in the URL, to answer the |
| 8707 | // challenge. |
| 8708 | MockWrite data_writes3[] = { |
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" |
| 8713 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8714 | }; |
| 8715 | |
| 8716 | MockRead data_reads3[] = { |
| 8717 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8718 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8719 | MockRead(SYNCHRONOUS, OK), |
| 8720 | }; |
| 8721 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8722 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8723 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8724 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8725 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 8726 | |
| 8727 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8728 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8729 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8730 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8731 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8732 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8733 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8734 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8735 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8736 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 8737 | |
| 8738 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8739 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8740 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8741 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8742 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8743 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8744 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8745 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8746 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8747 | |
| 8748 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8749 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8750 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8751 | |
| 8752 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8753 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8754 | } |
| 8755 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8756 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8757 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8758 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8759 | |
| 8760 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 8761 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8762 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8763 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8764 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8765 | request.traffic_annotation = |
| 8766 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8767 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8768 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8769 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8770 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8771 | MockWrite( |
| 8772 | "GET /x/y/z HTTP/1.1\r\n" |
| 8773 | "Host: www.example.org\r\n" |
| 8774 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8775 | }; |
| 8776 | |
| 8777 | MockRead data_reads1[] = { |
| 8778 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8779 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8780 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8781 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8782 | }; |
| 8783 | |
| 8784 | // Resend with authorization (username=foo, password=bar) |
| 8785 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8786 | MockWrite( |
| 8787 | "GET /x/y/z HTTP/1.1\r\n" |
| 8788 | "Host: www.example.org\r\n" |
| 8789 | "Connection: keep-alive\r\n" |
| 8790 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8791 | }; |
| 8792 | |
| 8793 | // Sever accepts the authorization. |
| 8794 | MockRead data_reads2[] = { |
| 8795 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8796 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8797 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8798 | }; |
| 8799 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8800 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8801 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8802 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8803 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8804 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8805 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8806 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8807 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8808 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8809 | |
| 8810 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8811 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8812 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8813 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8814 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8815 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8816 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8817 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8818 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8819 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8820 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8821 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8822 | |
| 8823 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8824 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8825 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8826 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8827 | ASSERT_TRUE(response); |
| 8828 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8829 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8830 | } |
| 8831 | |
| 8832 | // ------------------------------------------------------------------------ |
| 8833 | |
| 8834 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 8835 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8836 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8837 | request.method = "GET"; |
| 8838 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 8839 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8840 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8841 | request.traffic_annotation = |
| 8842 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8843 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8844 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8845 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8846 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8847 | MockWrite( |
| 8848 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8849 | "Host: www.example.org\r\n" |
| 8850 | "Connection: keep-alive\r\n" |
| 8851 | // Send preemptive authorization for MyRealm1 |
| 8852 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8853 | }; |
| 8854 | |
| 8855 | // The server didn't like the preemptive authorization, and |
| 8856 | // challenges us for a different realm (MyRealm2). |
| 8857 | MockRead data_reads1[] = { |
| 8858 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8859 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 8860 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8861 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8862 | }; |
| 8863 | |
| 8864 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 8865 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8866 | MockWrite( |
| 8867 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8868 | "Host: www.example.org\r\n" |
| 8869 | "Connection: keep-alive\r\n" |
| 8870 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8871 | }; |
| 8872 | |
| 8873 | // Sever accepts the authorization. |
| 8874 | MockRead data_reads2[] = { |
| 8875 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8876 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8877 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8878 | }; |
| 8879 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8880 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8881 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8882 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8883 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8884 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8885 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8886 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8887 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8888 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8889 | |
| 8890 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8891 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8892 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8893 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8894 | ASSERT_TRUE(response); |
| 8895 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8896 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8897 | EXPECT_EQ("http://www.example.org", |
| 8898 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8899 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 8900 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[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 callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8903 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8904 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 8905 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8906 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8907 | |
| 8908 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8909 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8910 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8911 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8912 | ASSERT_TRUE(response); |
| 8913 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8914 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8915 | } |
| 8916 | |
| 8917 | // ------------------------------------------------------------------------ |
| 8918 | |
| 8919 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 8920 | // succeed with preemptive authorization. |
| 8921 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8922 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8923 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8924 | request.url = GURL("http://www.example.org/x/y/z2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8925 | request.traffic_annotation = |
| 8926 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8927 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8928 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8929 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8930 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8931 | MockWrite( |
| 8932 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 8933 | "Host: www.example.org\r\n" |
| 8934 | "Connection: keep-alive\r\n" |
| 8935 | // The authorization for MyRealm1 gets sent preemptively |
| 8936 | // (since the url is in the same protection space) |
| 8937 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8938 | }; |
| 8939 | |
| 8940 | // Sever accepts the preemptive authorization |
| 8941 | MockRead data_reads1[] = { |
| 8942 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8943 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8944 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8945 | }; |
| 8946 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8947 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8948 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8949 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8950 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8951 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8952 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8953 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8954 | |
| 8955 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8956 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8957 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8958 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8959 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8960 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8961 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8962 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8963 | } |
| 8964 | |
| 8965 | // ------------------------------------------------------------------------ |
| 8966 | |
| 8967 | // Transaction 4: request another URL in MyRealm (however the |
| 8968 | // url is not known to belong to the protection space, so no pre-auth). |
| 8969 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8970 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8971 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8972 | request.url = GURL("http://www.example.org/x/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8973 | request.traffic_annotation = |
| 8974 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8975 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8976 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8977 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8978 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8979 | MockWrite( |
| 8980 | "GET /x/1 HTTP/1.1\r\n" |
| 8981 | "Host: www.example.org\r\n" |
| 8982 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8983 | }; |
| 8984 | |
| 8985 | MockRead data_reads1[] = { |
| 8986 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8987 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8988 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8989 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8990 | }; |
| 8991 | |
| 8992 | // Resend with authorization from MyRealm's cache. |
| 8993 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8994 | MockWrite( |
| 8995 | "GET /x/1 HTTP/1.1\r\n" |
| 8996 | "Host: www.example.org\r\n" |
| 8997 | "Connection: keep-alive\r\n" |
| 8998 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8999 | }; |
| 9000 | |
| 9001 | // Sever accepts the authorization. |
| 9002 | MockRead data_reads2[] = { |
| 9003 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9004 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9005 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9006 | }; |
| 9007 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9008 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9009 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9010 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9011 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9012 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9013 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9014 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9015 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9016 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9017 | |
| 9018 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9019 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9020 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9021 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9022 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9023 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9024 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9025 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9026 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9027 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9028 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9029 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9030 | ASSERT_TRUE(response); |
| 9031 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9032 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9033 | } |
| 9034 | |
| 9035 | // ------------------------------------------------------------------------ |
| 9036 | |
| 9037 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 9038 | // cached identity. Should invalidate and re-prompt. |
| 9039 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9040 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9041 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9042 | request.url = GURL("http://www.example.org/p/q/t"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9043 | request.traffic_annotation = |
| 9044 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9045 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9046 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9047 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9048 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9049 | MockWrite( |
| 9050 | "GET /p/q/t HTTP/1.1\r\n" |
| 9051 | "Host: www.example.org\r\n" |
| 9052 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9053 | }; |
| 9054 | |
| 9055 | MockRead data_reads1[] = { |
| 9056 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9057 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9058 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9059 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9060 | }; |
| 9061 | |
| 9062 | // Resend with authorization from cache for MyRealm. |
| 9063 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9064 | MockWrite( |
| 9065 | "GET /p/q/t HTTP/1.1\r\n" |
| 9066 | "Host: www.example.org\r\n" |
| 9067 | "Connection: keep-alive\r\n" |
| 9068 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9069 | }; |
| 9070 | |
| 9071 | // Sever rejects the authorization. |
| 9072 | MockRead data_reads2[] = { |
| 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 | // At this point we should prompt for new credentials for MyRealm. |
| 9080 | // Restart with username=foo3, password=foo4. |
| 9081 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9082 | MockWrite( |
| 9083 | "GET /p/q/t HTTP/1.1\r\n" |
| 9084 | "Host: www.example.org\r\n" |
| 9085 | "Connection: keep-alive\r\n" |
| 9086 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9087 | }; |
| 9088 | |
| 9089 | // Sever accepts the authorization. |
| 9090 | MockRead data_reads3[] = { |
| 9091 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9092 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9093 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9094 | }; |
| 9095 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9096 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9097 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 9098 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9099 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9100 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9101 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9102 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9103 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9104 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9105 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9106 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9107 | |
| 9108 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9109 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9110 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9111 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9112 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9113 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9114 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9115 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9116 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9117 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9118 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9119 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9120 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9121 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9122 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9123 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9124 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9125 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 9126 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9127 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9128 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9129 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9130 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9131 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9132 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9133 | ASSERT_TRUE(response); |
| 9134 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9135 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9136 | } |
| 9137 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9138 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9139 | // Tests that nonce count increments when multiple auth attempts |
| 9140 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9141 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 9142 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 9143 | new HttpAuthHandlerDigest::Factory(); |
| 9144 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 9145 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 9146 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9147 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9148 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9149 | |
| 9150 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 9151 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9152 | HttpRequestInfo request; |
| 9153 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9154 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9155 | request.traffic_annotation = |
| 9156 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9157 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9158 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9159 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9160 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9161 | MockWrite( |
| 9162 | "GET /x/y/z HTTP/1.1\r\n" |
| 9163 | "Host: www.example.org\r\n" |
| 9164 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9165 | }; |
| 9166 | |
| 9167 | MockRead data_reads1[] = { |
| 9168 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9169 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 9170 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9171 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9172 | }; |
| 9173 | |
| 9174 | // Resend with authorization (username=foo, password=bar) |
| 9175 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9176 | MockWrite( |
| 9177 | "GET /x/y/z HTTP/1.1\r\n" |
| 9178 | "Host: www.example.org\r\n" |
| 9179 | "Connection: keep-alive\r\n" |
| 9180 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9181 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 9182 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 9183 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9184 | }; |
| 9185 | |
| 9186 | // Sever accepts the authorization. |
| 9187 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9188 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9189 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9190 | }; |
| 9191 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9192 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9193 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9194 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9195 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9196 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9197 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9198 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9199 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9200 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9201 | |
| 9202 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9203 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9204 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9205 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9206 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9207 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9208 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9209 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9210 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9211 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9212 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9213 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9214 | |
| 9215 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9216 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9217 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9218 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9219 | ASSERT_TRUE(response); |
| 9220 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9221 | } |
| 9222 | |
| 9223 | // ------------------------------------------------------------------------ |
| 9224 | |
| 9225 | // Transaction 2: Request another resource in digestive's protection space. |
| 9226 | // This will preemptively add an Authorization header which should have an |
| 9227 | // "nc" value of 2 (as compared to 1 in the first use. |
| 9228 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9229 | HttpRequestInfo request; |
| 9230 | request.method = "GET"; |
| 9231 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 9232 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9233 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9234 | request.traffic_annotation = |
| 9235 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9236 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9237 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9238 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9239 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9240 | MockWrite( |
| 9241 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 9242 | "Host: www.example.org\r\n" |
| 9243 | "Connection: keep-alive\r\n" |
| 9244 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9245 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 9246 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 9247 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9248 | }; |
| 9249 | |
| 9250 | // Sever accepts the authorization. |
| 9251 | MockRead data_reads1[] = { |
| 9252 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9253 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9254 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9255 | }; |
| 9256 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9257 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9258 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9259 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9260 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9261 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9262 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9263 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9264 | |
| 9265 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9266 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9267 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9268 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9269 | ASSERT_TRUE(response); |
| 9270 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9271 | } |
| 9272 | } |
| 9273 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9274 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9275 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9276 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9277 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9278 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9279 | |
| 9280 | // Setup some state (which we expect ResetStateForRestart() will clear). |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 9281 | trans.read_buf_ = base::MakeRefCounted<IOBuffer>(15); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9282 | trans.read_buf_len_ = 15; |
| 9283 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9284 | |
| 9285 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9286 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9287 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9288 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9289 | response->response_time = base::Time::Now(); |
| 9290 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9291 | |
| 9292 | { // Setup state for response_.vary_data |
| 9293 | HttpRequestInfo request; |
| 9294 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 9295 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 9296 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9297 | request.extra_headers.SetHeader("Foo", "1"); |
| 9298 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9299 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9300 | } |
| 9301 | |
| 9302 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9303 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9304 | |
| 9305 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9306 | EXPECT_FALSE(trans.read_buf_); |
| 9307 | EXPECT_EQ(0, trans.read_buf_len_); |
| 9308 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9309 | EXPECT_FALSE(response->auth_challenge); |
| 9310 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 9311 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9312 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9313 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9314 | } |
| 9315 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9316 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9317 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9318 | HttpRequestInfo request; |
| 9319 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9320 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9321 | request.traffic_annotation = |
| 9322 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9323 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9324 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9325 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9326 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9327 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9328 | MockWrite( |
| 9329 | "GET / HTTP/1.1\r\n" |
| 9330 | "Host: www.example.org\r\n" |
| 9331 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9332 | }; |
| 9333 | |
| 9334 | MockRead data_reads[] = { |
| 9335 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9336 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9337 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9338 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9339 | }; |
| 9340 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 9341 | StaticSocketDataProvider ssl_bad_certificate; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9342 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9343 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9344 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9345 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9346 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9347 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9348 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9349 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9350 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9351 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9352 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9353 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9354 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9355 | |
| 9356 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9357 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9358 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9359 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9360 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9361 | |
| 9362 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9363 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9364 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9365 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9366 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9367 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9368 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9369 | } |
| 9370 | |
| 9371 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 9372 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9373 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9374 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9375 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9376 | |
| 9377 | HttpRequestInfo request; |
| 9378 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9379 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9380 | request.traffic_annotation = |
| 9381 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9382 | |
| 9383 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9384 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9385 | "Host: www.example.org:443\r\n" |
| 9386 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9387 | }; |
| 9388 | |
| 9389 | MockRead proxy_reads[] = { |
| 9390 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9391 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9392 | }; |
| 9393 | |
| 9394 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9395 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9396 | "Host: www.example.org:443\r\n" |
| 9397 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9398 | MockWrite("GET / HTTP/1.1\r\n" |
| 9399 | "Host: www.example.org\r\n" |
| 9400 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9401 | }; |
| 9402 | |
| 9403 | MockRead data_reads[] = { |
| 9404 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9405 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9406 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9407 | MockRead("Content-Length: 100\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 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9411 | StaticSocketDataProvider ssl_bad_certificate(proxy_reads, proxy_writes); |
| 9412 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9413 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9414 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9415 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9416 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9417 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9418 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9419 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9420 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9421 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9422 | |
| 9423 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9424 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9425 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9426 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9427 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9428 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9429 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9430 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9431 | |
| 9432 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9433 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9434 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9435 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9436 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9437 | |
| 9438 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9439 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9440 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9441 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9442 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9443 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9444 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9445 | } |
| 9446 | } |
| 9447 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9448 | |
| 9449 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9450 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9451 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9452 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9453 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9454 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9455 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9456 | |
| 9457 | HttpRequestInfo request; |
| 9458 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9459 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9460 | request.traffic_annotation = |
| 9461 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9462 | |
| 9463 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9464 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9465 | "Host: www.example.org:443\r\n" |
| 9466 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9467 | MockWrite("GET / HTTP/1.1\r\n" |
| 9468 | "Host: www.example.org\r\n" |
| 9469 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9470 | }; |
| 9471 | |
| 9472 | MockRead data_reads[] = { |
| 9473 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9474 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9475 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9476 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9477 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9478 | }; |
| 9479 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9480 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9481 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9482 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9483 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9484 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9485 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9486 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9487 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9488 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9489 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9490 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9491 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9492 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9493 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9494 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9495 | |
| 9496 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9497 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9498 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9499 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9500 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9501 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9502 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9503 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9504 | EXPECT_EQ(200, response->headers->response_code()); |
| 9505 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9506 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9507 | |
| 9508 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9509 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9510 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9511 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9512 | } |
| 9513 | |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9514 | // Test that an HTTPS Proxy can redirect a CONNECT request for main frames. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9515 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9516 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9517 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9518 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9519 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9520 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9521 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9522 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 9523 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 9524 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 9525 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9526 | HttpRequestInfo request; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9527 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9528 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9529 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9530 | request.traffic_annotation = |
| 9531 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9532 | |
| 9533 | MockWrite data_writes[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9534 | MockWrite(ASYNC, 0, |
| 9535 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9536 | "Host: www.example.org:443\r\n" |
| 9537 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9538 | }; |
| 9539 | |
| 9540 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9541 | // Pause on first read. |
| 9542 | MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 9543 | MockRead(ASYNC, 2, "HTTP/1.1 302 Redirect\r\n"), |
| 9544 | MockRead(ASYNC, 3, "Location: http://login.example.com/\r\n"), |
| 9545 | MockRead(ASYNC, 4, "Content-Length: 0\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9546 | }; |
| 9547 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9548 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9549 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9550 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9551 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9552 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9553 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9554 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9555 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9556 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9557 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9558 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9559 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9560 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9561 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
| 9562 | |
| 9563 | // Host resolution takes |kTimeIncrement|. |
| 9564 | FastForwardBy(kTimeIncrement); |
| 9565 | // Resolving the current request with |ResolveNow| will cause the pending |
| 9566 | // request to instantly complete, and the async connect will start as well. |
| 9567 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 9568 | |
| 9569 | // Connecting takes |kTimeIncrement|. |
| 9570 | FastForwardBy(kTimeIncrement); |
| 9571 | data.RunUntilPaused(); |
| 9572 | |
| 9573 | // The server takes |kTimeIncrement| to respond. |
| 9574 | FastForwardBy(kTimeIncrement); |
| 9575 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9576 | |
| 9577 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9578 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9579 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9580 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9581 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9582 | |
| 9583 | EXPECT_EQ(302, response->headers->response_code()); |
| 9584 | std::string url; |
| 9585 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 9586 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9587 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9588 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9589 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9590 | |
| 9591 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 9592 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9593 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9594 | // In the case of redirects from proxies, just as with all responses from |
| 9595 | // proxies, DNS and SSL times reflect timing to look up the destination's |
| 9596 | // name, and negotiate an SSL connection to it (Neither of which are done in |
| 9597 | // this case), which the DNS and SSL times for the proxy are all included in |
| 9598 | // connect_start / connect_end. See |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9599 | // HttpNetworkTransaction::OnHttpsProxyTunnelResponseRedirect |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9600 | |
| 9601 | EXPECT_TRUE(load_timing_info.connect_timing.dns_start.is_null()); |
| 9602 | EXPECT_TRUE(load_timing_info.connect_timing.dns_end.is_null()); |
| 9603 | EXPECT_TRUE(load_timing_info.connect_timing.ssl_start.is_null()); |
| 9604 | EXPECT_TRUE(load_timing_info.connect_timing.ssl_end.is_null()); |
| 9605 | |
| 9606 | EXPECT_EQ(start_time, load_timing_info.proxy_resolve_start); |
| 9607 | EXPECT_EQ(start_time, load_timing_info.proxy_resolve_end); |
| 9608 | EXPECT_EQ(start_time, load_timing_info.connect_timing.connect_start); |
| 9609 | EXPECT_EQ(start_time + 3 * kTimeIncrement, |
| 9610 | load_timing_info.connect_timing.connect_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9611 | |
| 9612 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 9613 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 9614 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9615 | } |
| 9616 | |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9617 | // Test that an HTTPS Proxy cannot redirect a CONNECT request for subresources. |
| 9618 | TEST_F(HttpNetworkTransactionTest, |
| 9619 | RedirectOfHttpsConnectSubresourceViaHttpsProxy) { |
| 9620 | base::HistogramTester histograms; |
| 9621 | session_deps_.proxy_resolution_service = |
| 9622 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9623 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9624 | TestNetLog net_log; |
| 9625 | session_deps_.net_log = &net_log; |
| 9626 | |
| 9627 | HttpRequestInfo request; |
| 9628 | request.method = "GET"; |
| 9629 | request.url = GURL("https://www.example.org/"); |
| 9630 | request.traffic_annotation = |
| 9631 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9632 | |
| 9633 | MockWrite data_writes[] = { |
| 9634 | MockWrite(ASYNC, 0, |
| 9635 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9636 | "Host: www.example.org:443\r\n" |
| 9637 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9638 | }; |
| 9639 | |
| 9640 | MockRead data_reads[] = { |
| 9641 | MockRead(ASYNC, 1, "HTTP/1.1 302 Redirect\r\n"), |
| 9642 | MockRead(ASYNC, 2, "Location: http://login.example.com/\r\n"), |
| 9643 | MockRead(ASYNC, 3, "Content-Length: 0\r\n\r\n"), |
| 9644 | }; |
| 9645 | |
| 9646 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
| 9647 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9648 | |
| 9649 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9650 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9651 | |
| 9652 | TestCompletionCallback callback; |
| 9653 | |
| 9654 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9655 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 9656 | |
| 9657 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 9658 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9659 | |
| 9660 | rv = callback.WaitForResult(); |
| 9661 | EXPECT_THAT(rv, IsError(ERR_HTTPS_PROXY_TUNNEL_RESPONSE_REDIRECT)); |
| 9662 | |
| 9663 | histograms.ExpectUniqueSample( |
| 9664 | "Net.Proxy.RedirectDuringConnect", |
| 9665 | HttpNetworkTransaction::kSubresourceByExplicitProxy, 1); |
| 9666 | } |
| 9667 | |
| 9668 | // Test that an HTTPS Proxy which was auto-detected cannot redirect a CONNECT |
| 9669 | // request for main frames. |
| 9670 | TEST_F(HttpNetworkTransactionTest, |
| 9671 | RedirectOfHttpsConnectViaAutoDetectedHttpsProxy) { |
| 9672 | base::HistogramTester histograms; |
| 9673 | session_deps_.proxy_resolution_service = |
| 9674 | ProxyResolutionService::CreateFixedFromAutoDetectedPacResult( |
| 9675 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9676 | TestNetLog net_log; |
| 9677 | session_deps_.net_log = &net_log; |
| 9678 | |
| 9679 | HttpRequestInfo request; |
| 9680 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
| 9681 | request.method = "GET"; |
| 9682 | request.url = GURL("https://www.example.org/"); |
| 9683 | request.traffic_annotation = |
| 9684 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9685 | |
| 9686 | MockWrite data_writes[] = { |
| 9687 | MockWrite(ASYNC, 0, |
| 9688 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9689 | "Host: www.example.org:443\r\n" |
| 9690 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9691 | }; |
| 9692 | |
| 9693 | MockRead data_reads[] = { |
| 9694 | MockRead(ASYNC, 1, "HTTP/1.1 302 Redirect\r\n"), |
| 9695 | MockRead(ASYNC, 2, "Location: http://login.example.com/\r\n"), |
| 9696 | MockRead(ASYNC, 3, "Content-Length: 0\r\n\r\n"), |
| 9697 | }; |
| 9698 | |
| 9699 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
| 9700 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9701 | |
| 9702 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9703 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9704 | |
| 9705 | TestCompletionCallback callback; |
| 9706 | |
| 9707 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9708 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 9709 | |
| 9710 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 9711 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9712 | |
| 9713 | rv = callback.WaitForResult(); |
| 9714 | EXPECT_THAT(rv, IsError(ERR_HTTPS_PROXY_TUNNEL_RESPONSE_REDIRECT)); |
| 9715 | |
| 9716 | histograms.ExpectUniqueSample( |
| 9717 | "Net.Proxy.RedirectDuringConnect", |
| 9718 | HttpNetworkTransaction::kMainFrameByAutoDetectedProxy, 1); |
| 9719 | } |
| 9720 | |
| 9721 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request for main |
| 9722 | // frames. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9723 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9724 | base::HistogramTester histograms; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9725 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9726 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9727 | TestNetLog net_log; |
| 9728 | session_deps_.net_log = &net_log; |
| 9729 | |
| 9730 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 9731 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 9732 | session_deps_.host_resolver->set_ondemand_mode(true); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9733 | |
| 9734 | HttpRequestInfo request; |
| 9735 | request.method = "GET"; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9736 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9737 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9738 | request.traffic_annotation = |
| 9739 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9740 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9741 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9742 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 9743 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9744 | spdy::SpdySerializedFrame goaway( |
| 9745 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9746 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9747 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9748 | CreateMockWrite(goaway, 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9749 | }; |
| 9750 | |
| 9751 | static const char* const kExtraHeaders[] = { |
| 9752 | "location", |
| 9753 | "http://login.example.com/", |
| 9754 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9755 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9756 | "302", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9757 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9758 | // Pause on first read. |
| 9759 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp, 2), |
| 9760 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9761 | }; |
| 9762 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9763 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9764 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9765 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9766 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9767 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9768 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9769 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9770 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9771 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9772 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9773 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9774 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9775 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9776 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9777 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9778 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9779 | // Host resolution takes |kTimeIncrement|. |
| 9780 | FastForwardBy(kTimeIncrement); |
| 9781 | // Resolving the current request with |ResolveNow| will cause the pending |
| 9782 | // request to instantly complete, and the async connect will start as well. |
| 9783 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 9784 | |
| 9785 | // Connecting takes |kTimeIncrement|. |
| 9786 | FastForwardBy(kTimeIncrement); |
| 9787 | data.RunUntilPaused(); |
| 9788 | |
| 9789 | FastForwardBy(kTimeIncrement); |
| 9790 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9791 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9792 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9793 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9794 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9795 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9796 | |
| 9797 | EXPECT_EQ(302, response->headers->response_code()); |
| 9798 | std::string url; |
| 9799 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 9800 | EXPECT_EQ("http://login.example.com/", url); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9801 | |
| 9802 | LoadTimingInfo load_timing_info; |
| 9803 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 9804 | |
| 9805 | EXPECT_FALSE(load_timing_info.socket_reused); |
| 9806 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
| 9807 | |
| 9808 | // No proxy resolution times, since there's no PAC script. |
| 9809 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 9810 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 9811 | |
| 9812 | // In the case of redirects from proxies, just as with all responses from |
| 9813 | // proxies, DNS and SSL times reflect timing to look up the destination's |
| 9814 | // name, and negotiate an SSL connection to it (Neither of which are done in |
| 9815 | // this case), which the DNS and SSL times for the proxy are all included in |
| 9816 | // connect_start / connect_end. See |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9817 | // HttpNetworkTransaction::OnHttpsProxyTunnelResponseRedirect. |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9818 | |
| 9819 | EXPECT_TRUE(load_timing_info.connect_timing.dns_start.is_null()); |
| 9820 | EXPECT_TRUE(load_timing_info.connect_timing.dns_end.is_null()); |
| 9821 | EXPECT_TRUE(load_timing_info.connect_timing.ssl_start.is_null()); |
| 9822 | EXPECT_TRUE(load_timing_info.connect_timing.ssl_end.is_null()); |
| 9823 | |
| 9824 | EXPECT_EQ(start_time, load_timing_info.connect_timing.connect_start); |
| 9825 | EXPECT_EQ(start_time + 3 * kTimeIncrement, |
| 9826 | load_timing_info.connect_timing.connect_end); |
| 9827 | |
| 9828 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 9829 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 9830 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9831 | |
| 9832 | histograms.ExpectUniqueSample( |
| 9833 | "Net.Proxy.RedirectDuringConnect", |
| 9834 | HttpNetworkTransaction::kMainFrameByExplicitProxy, 1); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9835 | } |
| 9836 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 9837 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9838 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9839 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9840 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9841 | |
| 9842 | HttpRequestInfo request; |
| 9843 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9844 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9845 | request.traffic_annotation = |
| 9846 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9847 | |
| 9848 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9849 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9850 | "Host: www.example.org:443\r\n" |
| 9851 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9852 | }; |
| 9853 | |
| 9854 | MockRead data_reads[] = { |
| 9855 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 9856 | MockRead("Content-Length: 23\r\n\r\n"), |
| 9857 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9858 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9859 | }; |
| 9860 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9861 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9862 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9863 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9864 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9865 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9866 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9867 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9868 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9869 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9870 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9871 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9872 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9873 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9874 | |
| 9875 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9876 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9877 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 9878 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9879 | } |
| 9880 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 9881 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9882 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9883 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9884 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9885 | |
| 9886 | HttpRequestInfo request; |
| 9887 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9888 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9889 | request.traffic_annotation = |
| 9890 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9891 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9892 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9893 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 9894 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9895 | spdy::SpdySerializedFrame rst( |
| 9896 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9897 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9898 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9899 | }; |
| 9900 | |
| 9901 | static const char* const kExtraHeaders[] = { |
| 9902 | "location", |
| 9903 | "http://login.example.com/", |
| 9904 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9905 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9906 | "404", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9907 | spdy::SpdySerializedFrame body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9908 | spdy_util_.ConstructSpdyDataFrame(1, "The host does not exist", true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9909 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9910 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9911 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9912 | }; |
| 9913 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9914 | SequencedSocketData data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9915 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9916 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9917 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9918 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9919 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9920 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9921 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9922 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9923 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9924 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9925 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9926 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9927 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9928 | |
| 9929 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9930 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9931 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 9932 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9933 | } |
| 9934 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9935 | // Test the request-challenge-retry sequence for basic auth, through |
| 9936 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9937 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9938 | HttpRequestInfo request; |
| 9939 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9940 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9941 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 9942 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9943 | request.traffic_annotation = |
| 9944 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9945 | |
| 9946 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9947 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9948 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9949 | "HTTPS myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9950 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9951 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9952 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9953 | |
| 9954 | // Since we have proxy, should try to establish tunnel. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9955 | spdy::SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9956 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 9957 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9958 | spdy::SpdySerializedFrame rst( |
| 9959 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9960 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9961 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9962 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9963 | // be issuing -- the final header line contains the credentials. |
| 9964 | const char* const kAuthCredentials[] = { |
| 9965 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 9966 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9967 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9968 | kAuthCredentials, base::size(kAuthCredentials) / 2, 3, |
| 9969 | HttpProxyConnectJob::kH2QuicTunnelPriority, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9970 | HostPortPair("www.example.org", 443))); |
| 9971 | // fetch https://www.example.org/ via HTTP |
| 9972 | const char get[] = |
| 9973 | "GET / HTTP/1.1\r\n" |
| 9974 | "Host: www.example.org\r\n" |
| 9975 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9976 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9977 | spdy_util_.ConstructSpdyDataFrame(3, get, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9978 | |
| 9979 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9980 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 9981 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9982 | }; |
| 9983 | |
| 9984 | // The proxy responds to the connect with a 407, using a persistent |
| 9985 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 9986 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9987 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9988 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 9989 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9990 | spdy::SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9991 | kAuthStatus, kAuthChallenge, base::size(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9992 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9993 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 9994 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9995 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 9996 | "Content-Length: 5\r\n\r\n"; |
| 9997 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9998 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9999 | spdy_util_.ConstructSpdyDataFrame(3, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10000 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 10001 | spdy_util_.ConstructSpdyDataFrame(3, "hello", false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10002 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10003 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 10004 | CreateMockRead(conn_resp, 4, ASYNC), |
| 10005 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 10006 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10007 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10008 | }; |
| 10009 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10010 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10011 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10012 | // Negotiate SPDY to the proxy |
| 10013 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10014 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10015 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10016 | // Vanilla SSL to the server |
| 10017 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10018 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10019 | |
| 10020 | TestCompletionCallback callback1; |
| 10021 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10022 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10023 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10024 | |
| 10025 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10026 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10027 | |
| 10028 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10029 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 10030 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10031 | log.GetEntries(&entries); |
| 10032 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 10033 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 10034 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10035 | ExpectLogContainsSomewhere( |
| 10036 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 10037 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 10038 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10039 | |
| 10040 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10041 | ASSERT_TRUE(response); |
| 10042 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10043 | EXPECT_EQ(407, response->headers->response_code()); |
| 10044 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10045 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10046 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10047 | |
| 10048 | TestCompletionCallback callback2; |
| 10049 | |
| 10050 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 10051 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10052 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10053 | |
| 10054 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10055 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10056 | |
| 10057 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10058 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10059 | |
| 10060 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10061 | EXPECT_EQ(200, response->headers->response_code()); |
| 10062 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 10063 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10064 | |
| 10065 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10066 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10067 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10068 | LoadTimingInfo load_timing_info; |
| 10069 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10070 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10071 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10072 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10073 | trans.reset(); |
| 10074 | session->CloseAllConnections(); |
| 10075 | } |
| 10076 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10077 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 10078 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10079 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10080 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10081 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10082 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 10083 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10084 | HttpRequestInfo request; |
| 10085 | HttpRequestInfo push_request; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10086 | request.traffic_annotation = |
| 10087 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10088 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10089 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10090 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10091 | push_request.method = "GET"; |
| 10092 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10093 | push_request.traffic_annotation = |
| 10094 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10095 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10096 | // Configure against https proxy server "myproxy:443". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10097 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10098 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10099 | "HTTPS myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10100 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10101 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10102 | |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10103 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10104 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10105 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10106 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10107 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10108 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10109 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10110 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10111 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10112 | |
| 10113 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10114 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10115 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10116 | }; |
| 10117 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10118 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10119 | nullptr, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 10120 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10121 | spdy::SpdySerializedFrame stream1_reply( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10122 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10123 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10124 | spdy::SpdySerializedFrame stream1_body( |
| 10125 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10126 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10127 | spdy::SpdySerializedFrame stream2_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 10128 | spdy_util_.ConstructSpdyDataFrame(2, "pushed", true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10129 | |
| 10130 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 10131 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 10132 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10133 | CreateMockRead(stream1_body, 4, ASYNC), |
| 10134 | CreateMockRead(stream2_body, 5, ASYNC), |
| 10135 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10136 | }; |
| 10137 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10138 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10139 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10140 | // Negotiate SPDY to the proxy |
| 10141 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10142 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10143 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10144 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10145 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10146 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10147 | TestCompletionCallback callback; |
| 10148 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10149 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10150 | |
| 10151 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10152 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10153 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10154 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10155 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10156 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10157 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10158 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10159 | |
| 10160 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10161 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10162 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 10163 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10164 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10165 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10166 | |
| 10167 | EXPECT_EQ(200, response->headers->response_code()); |
| 10168 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10169 | |
| 10170 | std::string response_data; |
| 10171 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10172 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10173 | EXPECT_EQ("hello!", response_data); |
| 10174 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10175 | LoadTimingInfo load_timing_info; |
| 10176 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10177 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10178 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10179 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10180 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10181 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10182 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 10183 | |
| 10184 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10185 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10186 | EXPECT_EQ("pushed", response_data); |
| 10187 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10188 | LoadTimingInfo push_load_timing_info; |
| 10189 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 10190 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 10191 | // The transactions should share a socket ID, despite being for different |
| 10192 | // origins. |
| 10193 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 10194 | push_load_timing_info.socket_log_id); |
| 10195 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10196 | trans.reset(); |
| 10197 | push_trans.reset(); |
| 10198 | session->CloseAllConnections(); |
| 10199 | } |
| 10200 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10201 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10202 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10203 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10204 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10205 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 10206 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10207 | HttpRequestInfo request; |
| 10208 | |
| 10209 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10210 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10211 | request.traffic_annotation = |
| 10212 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10213 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10214 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10215 | "https://myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10216 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10217 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10218 | |
| 10219 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10220 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10221 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10222 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10223 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10224 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10225 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10226 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10227 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10228 | spdy::SpdySerializedFrame push_rst( |
| 10229 | spdy_util_.ConstructSpdyRstStream(2, spdy::ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10230 | |
| 10231 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10232 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10233 | }; |
| 10234 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10235 | spdy::SpdySerializedFrame stream1_reply( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10236 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10237 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10238 | spdy::SpdySerializedFrame stream1_body( |
| 10239 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10240 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10241 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10242 | nullptr, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10243 | |
| 10244 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10245 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10246 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 10247 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 10248 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10249 | }; |
| 10250 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10251 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10252 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10253 | // Negotiate SPDY to the proxy |
| 10254 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10255 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10256 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10257 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10258 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10259 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10260 | TestCompletionCallback callback; |
| 10261 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10262 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10263 | |
| 10264 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10265 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10266 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10267 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10268 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10269 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10270 | |
| 10271 | EXPECT_EQ(200, response->headers->response_code()); |
| 10272 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10273 | |
| 10274 | std::string response_data; |
| 10275 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10276 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10277 | EXPECT_EQ("hello!", response_data); |
| 10278 | |
| 10279 | trans.reset(); |
| 10280 | session->CloseAllConnections(); |
| 10281 | } |
| 10282 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10283 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 10284 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10285 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10286 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10287 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10288 | proxy_delegate->set_trusted_spdy_proxy( |
| 10289 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 10290 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10291 | HttpRequestInfo request; |
| 10292 | |
| 10293 | request.method = "GET"; |
| 10294 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10295 | request.traffic_annotation = |
| 10296 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10297 | |
| 10298 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10299 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10300 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10301 | BoundTestNetLog log; |
| 10302 | session_deps_.net_log = log.bound().net_log(); |
| 10303 | |
| 10304 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10305 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10306 | proxy_delegate.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10307 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10308 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10309 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10310 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10311 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10312 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10313 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10314 | |
| 10315 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10316 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10317 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10318 | }; |
| 10319 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10320 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10321 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10322 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10323 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 10324 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 10325 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10326 | spdy::SpdySerializedFrame stream1_body( |
| 10327 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10328 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10329 | spdy::SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10330 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10331 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10332 | spdy::SpdySerializedFrame stream2_body( |
| 10333 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10334 | |
| 10335 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10336 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10337 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10338 | CreateMockRead(stream1_body, 4, ASYNC), |
| 10339 | CreateMockRead(stream2_body, 5, ASYNC), |
| 10340 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10341 | }; |
| 10342 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10343 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10344 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 10345 | // Negotiate SPDY to the proxy |
| 10346 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10347 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10348 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 10349 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10350 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10351 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10352 | TestCompletionCallback callback; |
| 10353 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10354 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10355 | |
| 10356 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10357 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10358 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10359 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10360 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10361 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10362 | |
| 10363 | EXPECT_EQ(200, response->headers->response_code()); |
| 10364 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10365 | |
| 10366 | std::string response_data; |
| 10367 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10368 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10369 | EXPECT_EQ("hello!", response_data); |
| 10370 | |
| 10371 | trans.reset(); |
| 10372 | session->CloseAllConnections(); |
| 10373 | } |
| 10374 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10375 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 10376 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10377 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10378 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10379 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10380 | |
| 10381 | HttpRequestInfo request; |
| 10382 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10383 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10384 | request.traffic_annotation = |
| 10385 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10386 | |
| 10387 | // Attempt to fetch the URL from a server with a bad cert |
| 10388 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10389 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10390 | "Host: www.example.org:443\r\n" |
| 10391 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10392 | }; |
| 10393 | |
| 10394 | MockRead bad_cert_reads[] = { |
| 10395 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10396 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10397 | }; |
| 10398 | |
| 10399 | // Attempt to fetch the URL with a good cert |
| 10400 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10401 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10402 | "Host: www.example.org:443\r\n" |
| 10403 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10404 | MockWrite("GET / HTTP/1.1\r\n" |
| 10405 | "Host: www.example.org\r\n" |
| 10406 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10407 | }; |
| 10408 | |
| 10409 | MockRead good_cert_reads[] = { |
| 10410 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 10411 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10412 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10413 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10414 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10415 | }; |
| 10416 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10417 | StaticSocketDataProvider ssl_bad_certificate(bad_cert_reads, bad_cert_writes); |
| 10418 | StaticSocketDataProvider data(good_cert_reads, good_data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10419 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 10420 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10421 | |
| 10422 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10423 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10424 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 10425 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10426 | |
| 10427 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10428 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10429 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10430 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10431 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10432 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10433 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10434 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10435 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10436 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10437 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10438 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10439 | |
| 10440 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10441 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10442 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10443 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10444 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10445 | |
| 10446 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10447 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10448 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10449 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10450 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10451 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10452 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10453 | } |
| 10454 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10455 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10456 | HttpRequestInfo request; |
| 10457 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10458 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10459 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10460 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10461 | request.traffic_annotation = |
| 10462 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10463 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10464 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10465 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10466 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10467 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10468 | MockWrite( |
| 10469 | "GET / HTTP/1.1\r\n" |
| 10470 | "Host: www.example.org\r\n" |
| 10471 | "Connection: keep-alive\r\n" |
| 10472 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10473 | }; |
| 10474 | |
| 10475 | // Lastly, the server responds with the actual content. |
| 10476 | MockRead data_reads[] = { |
| 10477 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10478 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10479 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10480 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10481 | }; |
| 10482 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10483 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10484 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10485 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10486 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10487 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10488 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10489 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10490 | |
| 10491 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10492 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10493 | } |
| 10494 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10495 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10496 | // Test user agent values, used both for the request header of the original |
| 10497 | // request, and the value returned by the HttpUserAgentSettings. nullptr means |
| 10498 | // no request header / no HttpUserAgentSettings object. |
| 10499 | const char* kTestUserAgents[] = {nullptr, "", "Foopy"}; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10500 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10501 | for (const char* setting_user_agent : kTestUserAgents) { |
| 10502 | if (!setting_user_agent) { |
| 10503 | session_deps_.http_user_agent_settings.reset(); |
| 10504 | } else { |
| 10505 | session_deps_.http_user_agent_settings = |
| 10506 | std::make_unique<StaticHttpUserAgentSettings>( |
| 10507 | std::string() /* accept-language */, setting_user_agent); |
| 10508 | } |
| 10509 | session_deps_.proxy_resolution_service = |
| 10510 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 10511 | TRAFFIC_ANNOTATION_FOR_TESTS); |
| 10512 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10513 | for (const char* request_user_agent : kTestUserAgents) { |
| 10514 | HttpRequestInfo request; |
| 10515 | request.method = "GET"; |
| 10516 | request.url = GURL("https://www.example.org/"); |
| 10517 | if (request_user_agent) { |
| 10518 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10519 | request_user_agent); |
| 10520 | } |
| 10521 | request.traffic_annotation = |
| 10522 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10523 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10524 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10525 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10526 | std::string expected_request; |
| 10527 | if (!setting_user_agent || strlen(setting_user_agent) == 0) { |
| 10528 | expected_request = |
| 10529 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10530 | "Host: www.example.org:443\r\n" |
| 10531 | "Proxy-Connection: keep-alive\r\n\r\n"; |
| 10532 | } else { |
| 10533 | expected_request = base::StringPrintf( |
| 10534 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10535 | "Host: www.example.org:443\r\n" |
| 10536 | "Proxy-Connection: keep-alive\r\n" |
| 10537 | "User-Agent: %s\r\n\r\n", |
| 10538 | setting_user_agent); |
| 10539 | } |
| 10540 | MockWrite data_writes[] = { |
| 10541 | MockWrite(expected_request.c_str()), |
| 10542 | }; |
| 10543 | MockRead data_reads[] = { |
| 10544 | // Return an error, so the transaction stops here (this test isn't |
| 10545 | // interested in the rest). |
| 10546 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 10547 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10548 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 10549 | }; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10550 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10551 | StaticSocketDataProvider data(data_reads, data_writes); |
| 10552 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10553 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10554 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10555 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10556 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 10557 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10558 | |
| 10559 | rv = callback.WaitForResult(); |
| 10560 | EXPECT_THAT(rv, IsOk()); |
| 10561 | } |
| 10562 | } |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10563 | } |
| 10564 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10565 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10566 | HttpRequestInfo request; |
| 10567 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10568 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 10569 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 10570 | "http://the.previous.site.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10571 | request.traffic_annotation = |
| 10572 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10573 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10574 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10575 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10576 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10577 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10578 | MockWrite( |
| 10579 | "GET / HTTP/1.1\r\n" |
| 10580 | "Host: www.example.org\r\n" |
| 10581 | "Connection: keep-alive\r\n" |
| 10582 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10583 | }; |
| 10584 | |
| 10585 | // Lastly, the server responds with the actual content. |
| 10586 | MockRead data_reads[] = { |
| 10587 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10588 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10589 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10590 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10591 | }; |
| 10592 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10593 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10594 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10595 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10596 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10597 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10598 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10599 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10600 | |
| 10601 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10602 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10603 | } |
| 10604 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10605 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10606 | HttpRequestInfo request; |
| 10607 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10608 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10609 | request.traffic_annotation = |
| 10610 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10611 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10612 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10613 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10614 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10615 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10616 | MockWrite( |
| 10617 | "POST / HTTP/1.1\r\n" |
| 10618 | "Host: www.example.org\r\n" |
| 10619 | "Connection: keep-alive\r\n" |
| 10620 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10621 | }; |
| 10622 | |
| 10623 | // Lastly, the server responds with the actual content. |
| 10624 | MockRead data_reads[] = { |
| 10625 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10626 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10627 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10628 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10629 | }; |
| 10630 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10631 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10632 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10633 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10634 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10635 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10636 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10637 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10638 | |
| 10639 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10640 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10641 | } |
| 10642 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10643 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10644 | HttpRequestInfo request; |
| 10645 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10646 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10647 | request.traffic_annotation = |
| 10648 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10649 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10650 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10651 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10652 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10653 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10654 | MockWrite( |
| 10655 | "PUT / HTTP/1.1\r\n" |
| 10656 | "Host: www.example.org\r\n" |
| 10657 | "Connection: keep-alive\r\n" |
| 10658 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10659 | }; |
| 10660 | |
| 10661 | // Lastly, the server responds with the actual content. |
| 10662 | MockRead data_reads[] = { |
| 10663 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10664 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10665 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10666 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10667 | }; |
| 10668 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10669 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10670 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10671 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10672 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10673 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10674 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10675 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10676 | |
| 10677 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10678 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10679 | } |
| 10680 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10681 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10682 | HttpRequestInfo request; |
| 10683 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10684 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10685 | request.traffic_annotation = |
| 10686 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10687 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10688 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10689 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10690 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10691 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 10692 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 10693 | "Host: www.example.org\r\n" |
| 10694 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10695 | }; |
| 10696 | |
| 10697 | // Lastly, the server responds with the actual content. |
| 10698 | MockRead data_reads[] = { |
| 10699 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10700 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10701 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10702 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10703 | }; |
| 10704 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10705 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10706 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10707 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10708 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10709 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10710 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10711 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10712 | |
| 10713 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10714 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10715 | } |
| 10716 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10717 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10718 | HttpRequestInfo request; |
| 10719 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10720 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10721 | request.load_flags = LOAD_BYPASS_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10722 | request.traffic_annotation = |
| 10723 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10724 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10725 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10726 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10727 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10728 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10729 | MockWrite( |
| 10730 | "GET / HTTP/1.1\r\n" |
| 10731 | "Host: www.example.org\r\n" |
| 10732 | "Connection: keep-alive\r\n" |
| 10733 | "Pragma: no-cache\r\n" |
| 10734 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10735 | }; |
| 10736 | |
| 10737 | // Lastly, the server responds with the actual content. |
| 10738 | MockRead data_reads[] = { |
| 10739 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10740 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10741 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10742 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10743 | }; |
| 10744 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10745 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10746 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10747 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10748 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10749 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10750 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10751 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10752 | |
| 10753 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10754 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10755 | } |
| 10756 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10757 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10758 | HttpRequestInfo request; |
| 10759 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10760 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10761 | request.load_flags = LOAD_VALIDATE_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10762 | request.traffic_annotation = |
| 10763 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10764 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10765 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10766 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10767 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10768 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10769 | MockWrite( |
| 10770 | "GET / HTTP/1.1\r\n" |
| 10771 | "Host: www.example.org\r\n" |
| 10772 | "Connection: keep-alive\r\n" |
| 10773 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10774 | }; |
| 10775 | |
| 10776 | // Lastly, the server responds with the actual content. |
| 10777 | MockRead data_reads[] = { |
| 10778 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10779 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10780 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10781 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10782 | }; |
| 10783 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10784 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10785 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10786 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10787 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10788 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10789 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10790 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10791 | |
| 10792 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10793 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10794 | } |
| 10795 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10796 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10797 | HttpRequestInfo request; |
| 10798 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10799 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10800 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10801 | request.traffic_annotation = |
| 10802 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10803 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10804 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10805 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10806 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10807 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10808 | MockWrite( |
| 10809 | "GET / HTTP/1.1\r\n" |
| 10810 | "Host: www.example.org\r\n" |
| 10811 | "Connection: keep-alive\r\n" |
| 10812 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10813 | }; |
| 10814 | |
| 10815 | // Lastly, the server responds with the actual content. |
| 10816 | MockRead data_reads[] = { |
| 10817 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10818 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10819 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10820 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10821 | }; |
| 10822 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10823 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10824 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10825 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10826 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10827 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10828 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10829 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10830 | |
| 10831 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10832 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10833 | } |
| 10834 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10835 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10836 | HttpRequestInfo request; |
| 10837 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10838 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10839 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 10840 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 10841 | request.extra_headers.SetHeader("FoO", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10842 | request.traffic_annotation = |
| 10843 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10844 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10845 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10846 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10847 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10848 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10849 | MockWrite( |
| 10850 | "GET / HTTP/1.1\r\n" |
| 10851 | "Host: www.example.org\r\n" |
| 10852 | "Connection: keep-alive\r\n" |
| 10853 | "referer: www.foo.com\r\n" |
| 10854 | "hEllo: Kitty\r\n" |
| 10855 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10856 | }; |
| 10857 | |
| 10858 | // Lastly, the server responds with the actual content. |
| 10859 | MockRead data_reads[] = { |
| 10860 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10861 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10862 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10863 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10864 | }; |
| 10865 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10866 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10867 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10868 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10869 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10870 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10871 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10872 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10873 | |
| 10874 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10875 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10876 | } |
| 10877 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10878 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10879 | HttpRequestInfo request; |
| 10880 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10881 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10882 | request.traffic_annotation = |
| 10883 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10884 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10885 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10886 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10887 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10888 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10889 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10890 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10891 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10892 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10893 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10894 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 10895 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10896 | |
| 10897 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10898 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 10899 | MockWrite("GET / HTTP/1.1\r\n" |
| 10900 | "Host: www.example.org\r\n" |
| 10901 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10902 | |
| 10903 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10904 | MockRead(ASYNC, read_buffer, 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] | 3cd1724 | 2009-06-23 02:59:02 | [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] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10911 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10912 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10913 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10914 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10915 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10916 | |
| 10917 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10918 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10919 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10920 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10921 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10922 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10923 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10924 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10925 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10926 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10927 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10928 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10929 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10930 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10931 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10932 | EXPECT_EQ("Payload", response_text); |
| 10933 | } |
| 10934 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10935 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10936 | HttpRequestInfo request; |
| 10937 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10938 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10939 | request.traffic_annotation = |
| 10940 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10941 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10942 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10943 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10944 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10945 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10946 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10947 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10948 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10949 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10950 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10951 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 10952 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10953 | |
| 10954 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10955 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10956 | base::size(write_buffer)), |
| 10957 | MockWrite("GET / HTTP/1.1\r\n" |
| 10958 | "Host: www.example.org\r\n" |
| 10959 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10960 | |
| 10961 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10962 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 10963 | 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] | e0c27be | 2009-07-15 13:09:35 | [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] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10970 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10971 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10972 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10973 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10974 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10975 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10976 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10977 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10978 | |
| 10979 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10980 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10981 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 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 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10985 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10986 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10987 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10988 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10989 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10990 | |
| 10991 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10992 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10993 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10994 | EXPECT_EQ("Payload", response_text); |
| 10995 | } |
| 10996 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10997 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10998 | HttpRequestInfo request; |
| 10999 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11000 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11001 | request.traffic_annotation = |
| 11002 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11003 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11004 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11005 | "socks4://myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11006 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11007 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11008 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11009 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11010 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11011 | |
| 11012 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 11013 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 11014 | |
| 11015 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11016 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 11017 | MockWrite("GET / HTTP/1.1\r\n" |
| 11018 | "Host: www.example.org\r\n" |
| 11019 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11020 | |
| 11021 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11022 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 11023 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11024 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11025 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11026 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11027 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11028 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11029 | |
| 11030 | TestCompletionCallback callback; |
| 11031 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11032 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11033 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11034 | |
| 11035 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11036 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11037 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11038 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11039 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11040 | |
| 11041 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11042 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11043 | TestLoadTimingNotReused(load_timing_info, |
| 11044 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 11045 | |
| 11046 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11047 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11048 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11049 | EXPECT_EQ("Payload", response_text); |
| 11050 | } |
| 11051 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11052 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11053 | HttpRequestInfo request; |
| 11054 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11055 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11056 | request.traffic_annotation = |
| 11057 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11058 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11059 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11060 | ProxyResolutionService::CreateFixedFromPacResult( |
| 11061 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11062 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11063 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11064 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11065 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11066 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11067 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11068 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 11069 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11070 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11071 | 0x05, // Version |
| 11072 | 0x01, // Command (CONNECT) |
| 11073 | 0x00, // Reserved. |
| 11074 | 0x03, // Address type (DOMAINNAME). |
| 11075 | 0x0F, // Length of domain (15) |
| 11076 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 11077 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11078 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11079 | const char kSOCKS5OkResponse[] = |
| 11080 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 11081 | |
| 11082 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11083 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
| 11084 | MockWrite(ASYNC, kSOCKS5OkRequest, base::size(kSOCKS5OkRequest)), |
| 11085 | MockWrite("GET / HTTP/1.1\r\n" |
| 11086 | "Host: www.example.org\r\n" |
| 11087 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11088 | |
| 11089 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11090 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 11091 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 11092 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11093 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11094 | MockRead("Payload"), |
| 11095 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11096 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11097 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11098 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11099 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11100 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11101 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11102 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11103 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11104 | |
| 11105 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11106 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11107 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11108 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11109 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11110 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11111 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11112 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11113 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11114 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11115 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 11116 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11117 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11118 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11119 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11120 | EXPECT_EQ("Payload", response_text); |
| 11121 | } |
| 11122 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11123 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11124 | HttpRequestInfo request; |
| 11125 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11126 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11127 | request.traffic_annotation = |
| 11128 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11129 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11130 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11131 | ProxyResolutionService::CreateFixedFromPacResult( |
| 11132 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11133 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11134 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11135 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11136 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11137 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11138 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11139 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 11140 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11141 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11142 | 0x05, // Version |
| 11143 | 0x01, // Command (CONNECT) |
| 11144 | 0x00, // Reserved. |
| 11145 | 0x03, // Address type (DOMAINNAME). |
| 11146 | 0x0F, // Length of domain (15) |
| 11147 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 11148 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11149 | }; |
| 11150 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11151 | const char kSOCKS5OkResponse[] = |
| 11152 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 11153 | |
| 11154 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11155 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11156 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11157 | base::size(kSOCKS5OkRequest)), |
| 11158 | MockWrite("GET / HTTP/1.1\r\n" |
| 11159 | "Host: www.example.org\r\n" |
| 11160 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11161 | |
| 11162 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11163 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 11164 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 11165 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11166 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11167 | MockRead("Payload"), |
| 11168 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11169 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11170 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11171 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11172 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11173 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11174 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11175 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11176 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11177 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11178 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11179 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11180 | |
| 11181 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11182 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11183 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11184 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11185 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11186 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11187 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11188 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11189 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11190 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11191 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 11192 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11193 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11194 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11195 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11196 | EXPECT_EQ("Payload", response_text); |
| 11197 | } |
| 11198 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11199 | namespace { |
| 11200 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11201 | // Tests that for connection endpoints the group ids are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11202 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11203 | struct GroupIdTest { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11204 | std::string proxy_server; |
| 11205 | std::string url; |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11206 | ClientSocketPool::GroupId expected_group_id; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 11207 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11208 | }; |
| 11209 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11210 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupIdTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11211 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11212 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11213 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11214 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11215 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11216 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11217 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11218 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 11219 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11220 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11221 | |
| 11222 | return session; |
| 11223 | } |
| 11224 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11225 | int GroupIdTransactionHelper(const std::string& url, |
| 11226 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11227 | HttpRequestInfo request; |
| 11228 | request.method = "GET"; |
| 11229 | request.url = GURL(url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11230 | request.traffic_annotation = |
| 11231 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11232 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11233 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11234 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11235 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11236 | |
| 11237 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11238 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11239 | } |
| 11240 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11241 | } // namespace |
| 11242 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11243 | TEST_F(HttpNetworkTransactionTest, GroupIdForDirectConnections) { |
| 11244 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11245 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11246 | "", // unused |
| 11247 | "http://www.example.org/direct", |
| 11248 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11249 | ClientSocketPool::SocketType::kHttp, |
| 11250 | false /* privacy_mode */), |
| 11251 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11252 | }, |
| 11253 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11254 | "", // unused |
| 11255 | "http://[2001:1418:13:1::25]/direct", |
| 11256 | ClientSocketPool::GroupId(HostPortPair("2001:1418:13:1::25", 80), |
| 11257 | ClientSocketPool::SocketType::kHttp, |
| 11258 | false /* privacy_mode */), |
| 11259 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11260 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11261 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11262 | // SSL Tests |
| 11263 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11264 | "", // unused |
| 11265 | "https://www.example.org/direct_ssl", |
| 11266 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11267 | ClientSocketPool::SocketType::kSsl, |
| 11268 | false /* privacy_mode */), |
| 11269 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11270 | }, |
| 11271 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11272 | "", // unused |
| 11273 | "https://[2001:1418:13:1::25]/direct", |
| 11274 | ClientSocketPool::GroupId(HostPortPair("2001:1418:13:1::25", 443), |
| 11275 | ClientSocketPool::SocketType::kSsl, |
| 11276 | false /* privacy_mode */), |
| 11277 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11278 | }, |
| 11279 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11280 | "", // unused |
| 11281 | "https://host.with.alternate/direct", |
| 11282 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11283 | ClientSocketPool::SocketType::kSsl, |
| 11284 | false /* privacy_mode */), |
| 11285 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11286 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11287 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11288 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11289 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11290 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11291 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11292 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11293 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11294 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11295 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11296 | HttpNetworkSessionPeer peer(session.get()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11297 | CaptureGroupIdTransportSocketPool* transport_conn_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame^] | 11298 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11299 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11300 | mock_pool_manager->SetSocketPool(ProxyServer::Direct(), |
| 11301 | base::WrapUnique(transport_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11302 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11303 | |
| 11304 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11305 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11306 | EXPECT_EQ(tests[i].expected_group_id, |
| 11307 | transport_conn_pool->last_group_id_received()); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 11308 | EXPECT_TRUE(transport_conn_pool->socket_requested()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11309 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11310 | } |
| 11311 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11312 | TEST_F(HttpNetworkTransactionTest, GroupIdForHTTPProxyConnections) { |
| 11313 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11314 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11315 | "http_proxy", |
| 11316 | "http://www.example.org/http_proxy_normal", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11317 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11318 | ClientSocketPool::SocketType::kHttp, |
| 11319 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11320 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11321 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11322 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11323 | // SSL Tests |
| 11324 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11325 | "http_proxy", |
| 11326 | "https://www.example.org/http_connect_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11327 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11328 | ClientSocketPool::SocketType::kSsl, |
| 11329 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11330 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11331 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11332 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11333 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11334 | "http_proxy", |
| 11335 | "https://host.with.alternate/direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11336 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11337 | ClientSocketPool::SocketType::kSsl, |
| 11338 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11339 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11340 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 11341 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11342 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11343 | "http_proxy", |
| 11344 | "ftp://ftp.google.com/http_proxy_normal", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11345 | ClientSocketPool::GroupId(HostPortPair("ftp.google.com", 21), |
| 11346 | ClientSocketPool::SocketType::kFtp, |
| 11347 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11348 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11349 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11350 | }; |
| 11351 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11352 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11353 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11354 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11355 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11356 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11357 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11358 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11359 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11360 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11361 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11362 | HostPortPair("http_proxy", 80)); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11363 | CaptureGroupIdTransportSocketPool* http_proxy_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame^] | 11364 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11365 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11366 | mock_pool_manager->SetSocketPool(proxy_server, |
| 11367 | base::WrapUnique(http_proxy_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11368 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11369 | |
| 11370 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11371 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11372 | EXPECT_EQ(tests[i].expected_group_id, |
| 11373 | http_proxy_pool->last_group_id_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11374 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11375 | } |
| 11376 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11377 | TEST_F(HttpNetworkTransactionTest, GroupIdForSOCKSConnections) { |
| 11378 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11379 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11380 | "socks4://socks_proxy:1080", |
| 11381 | "http://www.example.org/socks4_direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11382 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11383 | ClientSocketPool::SocketType::kHttp, |
| 11384 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11385 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11386 | }, |
| 11387 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11388 | "socks5://socks_proxy:1080", |
| 11389 | "http://www.example.org/socks5_direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11390 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11391 | ClientSocketPool::SocketType::kHttp, |
| 11392 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11393 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11394 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11395 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11396 | // SSL Tests |
| 11397 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11398 | "socks4://socks_proxy:1080", |
| 11399 | "https://www.example.org/socks4_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11400 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11401 | ClientSocketPool::SocketType::kSsl, |
| 11402 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11403 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11404 | }, |
| 11405 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11406 | "socks5://socks_proxy:1080", |
| 11407 | "https://www.example.org/socks5_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11408 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11409 | ClientSocketPool::SocketType::kSsl, |
| 11410 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11411 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11412 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11413 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11414 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11415 | "socks4://socks_proxy:1080", |
| 11416 | "https://host.with.alternate/direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11417 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11418 | ClientSocketPool::SocketType::kSsl, |
| 11419 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11420 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11421 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11422 | }; |
| 11423 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11424 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11425 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11426 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11427 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11428 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11429 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 11430 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11431 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11432 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11433 | ProxyServer proxy_server( |
| 11434 | ProxyServer::FromURI(tests[i].proxy_server, ProxyServer::SCHEME_HTTP)); |
| 11435 | ASSERT_TRUE(proxy_server.is_valid()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11436 | CaptureGroupIdTransportSocketPool* socks_conn_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame^] | 11437 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11438 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11439 | mock_pool_manager->SetSocketPool(proxy_server, |
| 11440 | base::WrapUnique(socks_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11441 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11442 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11443 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11444 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11445 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11446 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11447 | EXPECT_EQ(tests[i].expected_group_id, |
| 11448 | socks_conn_pool->last_group_id_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11449 | } |
| 11450 | } |
| 11451 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11452 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11453 | HttpRequestInfo request; |
| 11454 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11455 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11456 | request.traffic_annotation = |
| 11457 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11458 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11459 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11460 | "myproxy:70;foobar:80", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11461 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 11462 | // This simulates failure resolving all hostnames; that means we will fail |
| 11463 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11464 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11465 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11466 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11467 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11468 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11469 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11470 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11471 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11472 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11473 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11474 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11475 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11476 | } |
| 11477 | |
Miriam Gershenson | 2a01b16 | 2018-03-22 22:54:47 | [diff] [blame] | 11478 | // LOAD_BYPASS_CACHE should trigger the host cache bypass. |
| 11479 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11480 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 11481 | HttpRequestInfo request_info; |
| 11482 | request_info.method = "GET"; |
Miriam Gershenson | 2a01b16 | 2018-03-22 22:54:47 | [diff] [blame] | 11483 | request_info.load_flags = LOAD_BYPASS_CACHE; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 11484 | request_info.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11485 | request_info.traffic_annotation = |
| 11486 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11487 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 11488 | // Select a host resolver that does caching. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11489 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11490 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11491 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11492 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11493 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11494 | // Warm up the host cache so it has an entry for "www.example.org". |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 11495 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 11496 | HostPortPair("www.example.org", 80), base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11497 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11498 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11499 | // Inject a failure the next time that "www.example.org" is resolved. This way |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11500 | // we can tell if the next lookup hit the cache, or the "network". |
| 11501 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11502 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11503 | |
| 11504 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 11505 | // first read -- this won't be reached as the host resolution will fail first. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11506 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11507 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11508 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11509 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11510 | // Run the request. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 11511 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11512 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11513 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11514 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11515 | |
| 11516 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11517 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11518 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11519 | } |
| 11520 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11521 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11522 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11523 | HttpRequestInfo request; |
| 11524 | request.method = "GET"; |
| 11525 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11526 | request.traffic_annotation = |
| 11527 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11528 | |
| 11529 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11530 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11531 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11532 | StaticSocketDataProvider data(base::span<MockRead>(), write_failure); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11533 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11534 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11535 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11536 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11537 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11538 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11539 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11540 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11541 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11542 | |
| 11543 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11544 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11545 | |
| 11546 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11547 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11548 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11549 | } |
| 11550 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11551 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11552 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11553 | HttpRequestInfo request; |
| 11554 | request.method = "GET"; |
| 11555 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11556 | request.traffic_annotation = |
| 11557 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11558 | |
| 11559 | MockRead data_reads[] = { |
| 11560 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11561 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11562 | }; |
| 11563 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11564 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11565 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11566 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11567 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11568 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11569 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11570 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11571 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11572 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11573 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11574 | |
| 11575 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11576 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11577 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11578 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11579 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11580 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11581 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11582 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11583 | |
| 11584 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11585 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11586 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11587 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11588 | |
| 11589 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11590 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11591 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11592 | } |
| 11593 | |
| 11594 | // Make sure that a dropped connection while draining the body for auth |
| 11595 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11596 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11597 | HttpRequestInfo request; |
| 11598 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11599 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11600 | request.traffic_annotation = |
| 11601 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11602 | |
| 11603 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11604 | MockWrite( |
| 11605 | "GET / HTTP/1.1\r\n" |
| 11606 | "Host: www.example.org\r\n" |
| 11607 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11608 | }; |
| 11609 | |
| 11610 | MockRead data_reads1[] = { |
| 11611 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 11612 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 11613 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11614 | MockRead("Content-Length: 14\r\n\r\n"), |
| 11615 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11616 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11617 | }; |
| 11618 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11619 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11620 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11621 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11622 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11623 | // be issuing -- the final header line contains the credentials. |
| 11624 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11625 | MockWrite( |
| 11626 | "GET / HTTP/1.1\r\n" |
| 11627 | "Host: www.example.org\r\n" |
| 11628 | "Connection: keep-alive\r\n" |
| 11629 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11630 | }; |
| 11631 | |
| 11632 | // Lastly, the server responds with the actual content. |
| 11633 | MockRead data_reads2[] = { |
| 11634 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11635 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11636 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11637 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11638 | }; |
| 11639 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11640 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11641 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11642 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11643 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11644 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11645 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11646 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11647 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11648 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11649 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11650 | |
| 11651 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11652 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11653 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11654 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11655 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11656 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11657 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11658 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11659 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11660 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11661 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11662 | |
| 11663 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11664 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11665 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11666 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11667 | ASSERT_TRUE(response); |
| 11668 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11669 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11670 | } |
| 11671 | |
| 11672 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11673 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11674 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11675 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11676 | |
| 11677 | HttpRequestInfo request; |
| 11678 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11679 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11680 | request.traffic_annotation = |
| 11681 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11682 | |
| 11683 | MockRead proxy_reads[] = { |
| 11684 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11685 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11686 | }; |
| 11687 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11688 | StaticSocketDataProvider data(proxy_reads, base::span<MockWrite>()); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11689 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11690 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11691 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11692 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11693 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11694 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11695 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11696 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11697 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11698 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11699 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11700 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11701 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11702 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11703 | |
| 11704 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11705 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11706 | } |
| 11707 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11708 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11709 | HttpRequestInfo request; |
| 11710 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11711 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11712 | request.traffic_annotation = |
| 11713 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11714 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11715 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11716 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11717 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11718 | MockRead data_reads[] = { |
| 11719 | 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] | 11720 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11721 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11722 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11723 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11724 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11725 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11726 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11727 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11728 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11729 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11730 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11731 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11732 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11733 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11734 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11735 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11736 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11737 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11738 | |
| 11739 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11740 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11741 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11742 | } |
| 11743 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11744 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11745 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11746 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11747 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 11748 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 11749 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11750 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11751 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11752 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11753 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11754 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11755 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11756 | |
| 11757 | HttpRequestInfo request; |
| 11758 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11759 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11760 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11761 | request.traffic_annotation = |
| 11762 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11763 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11764 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11765 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11766 | |
| 11767 | MockRead data_reads[] = { |
| 11768 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 11769 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11770 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11771 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11772 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11773 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11774 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11775 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11776 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11777 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11778 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11779 | |
| 11780 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11781 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11782 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11783 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11784 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11785 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 11786 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11787 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11788 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11789 | } |
| 11790 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11791 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11792 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11793 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11794 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 11795 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 11796 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 11797 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 11798 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11799 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11800 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11801 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11802 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11803 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11804 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11805 | |
| 11806 | HttpRequestInfo request; |
| 11807 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11808 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11809 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11810 | request.traffic_annotation = |
| 11811 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11812 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 11813 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11814 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11815 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11816 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11817 | StaticSocketDataProvider data; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11818 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11819 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11820 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11821 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11822 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11823 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11824 | |
| 11825 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11826 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11827 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11828 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11829 | } |
| 11830 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11831 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11832 | class FakeUploadElementReader : public UploadElementReader { |
| 11833 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 11834 | FakeUploadElementReader() = default; |
| 11835 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11836 | |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11837 | CompletionOnceCallback TakeCallback() { return std::move(callback_); } |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11838 | |
| 11839 | // UploadElementReader overrides: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11840 | int Init(CompletionOnceCallback callback) override { |
| 11841 | callback_ = std::move(callback); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11842 | return ERR_IO_PENDING; |
| 11843 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11844 | uint64_t GetContentLength() const override { return 0; } |
| 11845 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11846 | int Read(IOBuffer* buf, |
| 11847 | int buf_length, |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11848 | CompletionOnceCallback callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11849 | return ERR_FAILED; |
| 11850 | } |
| 11851 | |
| 11852 | private: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11853 | CompletionOnceCallback callback_; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11854 | }; |
| 11855 | |
| 11856 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11857 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 11858 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11859 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11860 | |
| 11861 | HttpRequestInfo request; |
| 11862 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11863 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11864 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11865 | request.traffic_annotation = |
| 11866 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11867 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11868 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11869 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11870 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11871 | |
| 11872 | StaticSocketDataProvider data; |
| 11873 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11874 | |
| 11875 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11876 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11877 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 11878 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11879 | |
| 11880 | // Transaction is pending on request body initialization. |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11881 | CompletionOnceCallback init_callback = fake_reader->TakeCallback(); |
| 11882 | ASSERT_FALSE(init_callback.is_null()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11883 | |
| 11884 | // Return Init()'s result after the transaction gets destroyed. |
| 11885 | trans.reset(); |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11886 | std::move(init_callback).Run(OK); // Should not crash. |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11887 | } |
| 11888 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11889 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11890 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11891 | HttpRequestInfo request; |
| 11892 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11893 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11894 | request.traffic_annotation = |
| 11895 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11896 | |
| 11897 | // First transaction will request a resource and receive a Basic challenge |
| 11898 | // with realm="first_realm". |
| 11899 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11900 | MockWrite( |
| 11901 | "GET / HTTP/1.1\r\n" |
| 11902 | "Host: www.example.org\r\n" |
| 11903 | "Connection: keep-alive\r\n" |
| 11904 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11905 | }; |
| 11906 | MockRead data_reads1[] = { |
| 11907 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11908 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 11909 | "\r\n"), |
| 11910 | }; |
| 11911 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11912 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11913 | // for first_realm. The server will reject and provide a challenge with |
| 11914 | // second_realm. |
| 11915 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11916 | MockWrite( |
| 11917 | "GET / HTTP/1.1\r\n" |
| 11918 | "Host: www.example.org\r\n" |
| 11919 | "Connection: keep-alive\r\n" |
| 11920 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 11921 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11922 | }; |
| 11923 | MockRead data_reads2[] = { |
| 11924 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11925 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 11926 | "\r\n"), |
| 11927 | }; |
| 11928 | |
| 11929 | // This again fails, and goes back to first_realm. Make sure that the |
| 11930 | // entry is removed from cache. |
| 11931 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11932 | MockWrite( |
| 11933 | "GET / HTTP/1.1\r\n" |
| 11934 | "Host: www.example.org\r\n" |
| 11935 | "Connection: keep-alive\r\n" |
| 11936 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 11937 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11938 | }; |
| 11939 | MockRead data_reads3[] = { |
| 11940 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11941 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 11942 | "\r\n"), |
| 11943 | }; |
| 11944 | |
| 11945 | // Try one last time (with the correct password) and get the resource. |
| 11946 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11947 | MockWrite( |
| 11948 | "GET / HTTP/1.1\r\n" |
| 11949 | "Host: www.example.org\r\n" |
| 11950 | "Connection: keep-alive\r\n" |
| 11951 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 11952 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11953 | }; |
| 11954 | MockRead data_reads4[] = { |
| 11955 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11956 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11957 | "Content-Length: 5\r\n" |
| 11958 | "\r\n" |
| 11959 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11960 | }; |
| 11961 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11962 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 11963 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 11964 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
| 11965 | StaticSocketDataProvider data4(data_reads4, data_writes4); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11966 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 11967 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 11968 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 11969 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11970 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11971 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11972 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11973 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11974 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11975 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11976 | // Issue the first request with Authorize headers. There should be a |
| 11977 | // password prompt for first_realm waiting to be filled in after the |
| 11978 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11979 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11980 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11981 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11982 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11983 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11984 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11985 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11986 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11987 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11988 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11989 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11990 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11991 | |
| 11992 | // Issue the second request with an incorrect password. There should be a |
| 11993 | // password prompt for second_realm waiting to be filled in after the |
| 11994 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11995 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11996 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 11997 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11998 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11999 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12000 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12001 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12002 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 12003 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12004 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 12005 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 12006 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 12007 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 12008 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12009 | |
| 12010 | // Issue the third request with another incorrect password. There should be |
| 12011 | // a password prompt for first_realm waiting to be filled in. If the password |
| 12012 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 12013 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12014 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12015 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 12016 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12017 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12018 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12019 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12020 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12021 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 12022 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12023 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 12024 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 12025 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 12026 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 12027 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12028 | |
| 12029 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12030 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12031 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 12032 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12033 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12034 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12035 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12036 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12037 | ASSERT_TRUE(response); |
| 12038 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12039 | } |
| 12040 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12041 | // Regression test for https://crbug.com/754395. |
| 12042 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 12043 | MockRead data_reads[] = { |
| 12044 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12045 | MockRead(kAlternativeServiceHttpHeader), |
| 12046 | MockRead("\r\n"), |
| 12047 | MockRead("hello world"), |
| 12048 | MockRead(SYNCHRONOUS, OK), |
| 12049 | }; |
| 12050 | |
| 12051 | HttpRequestInfo request; |
| 12052 | request.method = "GET"; |
| 12053 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12054 | request.traffic_annotation = |
| 12055 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12056 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12057 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12058 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12059 | |
| 12060 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12061 | ssl.ssl_info.cert = |
| 12062 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12063 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 12064 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12065 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12066 | |
| 12067 | TestCompletionCallback callback; |
| 12068 | |
| 12069 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12070 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12071 | |
| 12072 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 12073 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12074 | |
| 12075 | url::SchemeHostPort test_server(request.url); |
| 12076 | HttpServerProperties* http_server_properties = |
| 12077 | session->http_server_properties(); |
| 12078 | EXPECT_TRUE( |
| 12079 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 12080 | |
| 12081 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 12082 | |
| 12083 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 12084 | ASSERT_TRUE(response); |
| 12085 | ASSERT_TRUE(response->headers); |
| 12086 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12087 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 12088 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 12089 | |
| 12090 | std::string response_data; |
| 12091 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 12092 | EXPECT_EQ("hello world", response_data); |
| 12093 | |
| 12094 | EXPECT_TRUE( |
| 12095 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 12096 | } |
| 12097 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12098 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12099 | MockRead data_reads[] = { |
| 12100 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12101 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12102 | MockRead("\r\n"), |
| 12103 | MockRead("hello world"), |
| 12104 | MockRead(SYNCHRONOUS, OK), |
| 12105 | }; |
| 12106 | |
| 12107 | HttpRequestInfo request; |
| 12108 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12109 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12110 | request.traffic_annotation = |
| 12111 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12112 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12113 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12114 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12115 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12116 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12117 | ssl.ssl_info.cert = |
| 12118 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12119 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12120 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12121 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12122 | TestCompletionCallback callback; |
| 12123 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12124 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12125 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12126 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12127 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12128 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12129 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12130 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12131 | HttpServerProperties* http_server_properties = |
| 12132 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12133 | EXPECT_TRUE( |
| 12134 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12135 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12136 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12137 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12138 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12139 | ASSERT_TRUE(response); |
| 12140 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12141 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12142 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12143 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12144 | |
| 12145 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12146 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12147 | EXPECT_EQ("hello world", response_data); |
| 12148 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12149 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 12150 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 12151 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 12152 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 12153 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12154 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12155 | } |
| 12156 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12157 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12158 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12159 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12160 | MockRead data_reads[] = { |
| 12161 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12162 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12163 | MockRead("\r\n"), |
| 12164 | MockRead("hello world"), |
| 12165 | MockRead(SYNCHRONOUS, OK), |
| 12166 | }; |
| 12167 | |
| 12168 | HttpRequestInfo request; |
| 12169 | request.method = "GET"; |
| 12170 | request.url = GURL("http://www.example.org/"); |
| 12171 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12172 | request.traffic_annotation = |
| 12173 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12174 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12175 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12176 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12177 | |
| 12178 | TestCompletionCallback callback; |
| 12179 | |
| 12180 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12181 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12182 | |
| 12183 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12184 | HttpServerProperties* http_server_properties = |
| 12185 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12186 | EXPECT_TRUE( |
| 12187 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12188 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12189 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12190 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12191 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12192 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12193 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12194 | ASSERT_TRUE(response); |
| 12195 | ASSERT_TRUE(response->headers); |
| 12196 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12197 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12198 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12199 | |
| 12200 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12201 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12202 | EXPECT_EQ("hello world", response_data); |
| 12203 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12204 | EXPECT_TRUE( |
| 12205 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12206 | } |
| 12207 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 12208 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12209 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12210 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12211 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 12212 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12213 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12214 | HttpRequestInfo request; |
| 12215 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12216 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12217 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12218 | request.traffic_annotation = |
| 12219 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12220 | |
| 12221 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12222 | StaticSocketDataProvider first_data; |
| 12223 | first_data.set_connect_data(mock_connect); |
| 12224 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12225 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12226 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12227 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12228 | |
| 12229 | MockRead data_reads[] = { |
| 12230 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12231 | MockRead(ASYNC, OK), |
| 12232 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12233 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12234 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12235 | |
| 12236 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12237 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12238 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12239 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12240 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 12241 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12242 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12243 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12244 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 12245 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12246 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12247 | TestCompletionCallback callback; |
| 12248 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12249 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12250 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12251 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12252 | } |
| 12253 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12254 | // Regression test for https://crbug.com/615497: |
| 12255 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12256 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12257 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12258 | HttpRequestInfo request; |
| 12259 | request.method = "GET"; |
| 12260 | request.url = GURL("http://www.example.org/"); |
| 12261 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12262 | request.traffic_annotation = |
| 12263 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12264 | |
| 12265 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12266 | StaticSocketDataProvider first_data; |
| 12267 | first_data.set_connect_data(mock_connect); |
| 12268 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 12269 | |
| 12270 | MockRead data_reads[] = { |
| 12271 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12272 | MockRead(ASYNC, OK), |
| 12273 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12274 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12275 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12276 | |
| 12277 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12278 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12279 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12280 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12281 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12282 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12283 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12284 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 12285 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12286 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12287 | TestCompletionCallback callback; |
| 12288 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12289 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12290 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12291 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12292 | } |
| 12293 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12294 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12295 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12296 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12297 | HttpServerProperties* http_server_properties = |
| 12298 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12299 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12300 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12301 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12302 | http_server_properties->SetQuicAlternativeService( |
| 12303 | test_server, alternative_service, expiration, |
| 12304 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12305 | EXPECT_EQ( |
| 12306 | 1u, |
| 12307 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12308 | |
| 12309 | // Send a clear header. |
| 12310 | MockRead data_reads[] = { |
| 12311 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12312 | MockRead("Alt-Svc: clear\r\n"), |
| 12313 | MockRead("\r\n"), |
| 12314 | MockRead("hello world"), |
| 12315 | MockRead(SYNCHRONOUS, OK), |
| 12316 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12317 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12318 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12319 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12320 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12321 | ssl.ssl_info.cert = |
| 12322 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12323 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12324 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12325 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12326 | HttpRequestInfo request; |
| 12327 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12328 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12329 | request.traffic_annotation = |
| 12330 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12331 | |
| 12332 | TestCompletionCallback callback; |
| 12333 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12334 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12335 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12336 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12337 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12338 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12339 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12340 | ASSERT_TRUE(response); |
| 12341 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12342 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12343 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12344 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12345 | |
| 12346 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12347 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12348 | EXPECT_EQ("hello world", response_data); |
| 12349 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12350 | EXPECT_TRUE( |
| 12351 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12352 | } |
| 12353 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12354 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12355 | MockRead data_reads[] = { |
| 12356 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12357 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 12358 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12359 | MockRead("hello world"), |
| 12360 | MockRead(SYNCHRONOUS, OK), |
| 12361 | }; |
| 12362 | |
| 12363 | HttpRequestInfo request; |
| 12364 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12365 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12366 | request.traffic_annotation = |
| 12367 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12368 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12369 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12370 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12371 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12372 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12373 | ssl.ssl_info.cert = |
| 12374 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12375 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12376 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12377 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12378 | TestCompletionCallback callback; |
| 12379 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12380 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12381 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12382 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12383 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12384 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12385 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12386 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12387 | HttpServerProperties* http_server_properties = |
| 12388 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12389 | EXPECT_TRUE( |
| 12390 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12391 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12392 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12393 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12394 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12395 | ASSERT_TRUE(response); |
| 12396 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12397 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12398 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12399 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12400 | |
| 12401 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12402 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12403 | EXPECT_EQ("hello world", response_data); |
| 12404 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12405 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 12406 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 12407 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 12408 | |
| 12409 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 12410 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12411 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12412 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 12413 | 1234); |
| 12414 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12415 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12416 | } |
| 12417 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12418 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12419 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12420 | HostPortPair alternative("alternative.example.org", 443); |
| 12421 | std::string origin_url = "https://origin.example.org:443"; |
| 12422 | std::string alternative_url = "https://alternative.example.org:443"; |
| 12423 | |
| 12424 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12425 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12426 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12427 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12428 | |
| 12429 | // HTTP/1.1 data for request. |
| 12430 | MockWrite http_writes[] = { |
| 12431 | MockWrite("GET / HTTP/1.1\r\n" |
| 12432 | "Host: alternative.example.org\r\n" |
| 12433 | "Connection: keep-alive\r\n\r\n"), |
| 12434 | }; |
| 12435 | |
| 12436 | MockRead http_reads[] = { |
| 12437 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12438 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12439 | "Content-Length: 40\r\n\r\n" |
| 12440 | "first HTTP/1.1 response from alternative"), |
| 12441 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12442 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12443 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12444 | |
| 12445 | StaticSocketDataProvider data_refused; |
| 12446 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12447 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12448 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12449 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12450 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12451 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12452 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12453 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12454 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12455 | http_server_properties->SetQuicAlternativeService( |
| 12456 | server, alternative_service, expiration, |
| 12457 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12458 | // Mark the QUIC alternative service as broken. |
| 12459 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 12460 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12461 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12462 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12463 | request.method = "GET"; |
| 12464 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12465 | request.traffic_annotation = |
| 12466 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12467 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12468 | TestCompletionCallback callback; |
| 12469 | NetErrorDetails details; |
| 12470 | EXPECT_FALSE(details.quic_broken); |
| 12471 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12472 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12473 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12474 | EXPECT_TRUE(details.quic_broken); |
| 12475 | } |
| 12476 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12477 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12478 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12479 | HostPortPair alternative1("alternative1.example.org", 443); |
| 12480 | HostPortPair alternative2("alternative2.example.org", 443); |
| 12481 | std::string origin_url = "https://origin.example.org:443"; |
| 12482 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 12483 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 12484 | |
| 12485 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 12486 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12487 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12488 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12489 | |
| 12490 | // HTTP/1.1 data for request. |
| 12491 | MockWrite http_writes[] = { |
| 12492 | MockWrite("GET / HTTP/1.1\r\n" |
| 12493 | "Host: alternative1.example.org\r\n" |
| 12494 | "Connection: keep-alive\r\n\r\n"), |
| 12495 | }; |
| 12496 | |
| 12497 | MockRead http_reads[] = { |
| 12498 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12499 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12500 | "Content-Length: 40\r\n\r\n" |
| 12501 | "first HTTP/1.1 response from alternative1"), |
| 12502 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12503 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12504 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12505 | |
| 12506 | StaticSocketDataProvider data_refused; |
| 12507 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12508 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12509 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12510 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12511 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12512 | session->http_server_properties(); |
| 12513 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12514 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12515 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 12516 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 12517 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12518 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12519 | alternative_service_info_vector.push_back( |
| 12520 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12521 | alternative_service1, expiration, |
| 12522 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12523 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12524 | alternative_service_info_vector.push_back( |
| 12525 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12526 | alternative_service2, expiration, |
| 12527 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12528 | |
| 12529 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12530 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12531 | |
| 12532 | // Mark one of the QUIC alternative service as broken. |
| 12533 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12534 | EXPECT_EQ(2u, |
| 12535 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12536 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12537 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12538 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12539 | request.method = "GET"; |
| 12540 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12541 | request.traffic_annotation = |
| 12542 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12543 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12544 | TestCompletionCallback callback; |
| 12545 | NetErrorDetails details; |
| 12546 | EXPECT_FALSE(details.quic_broken); |
| 12547 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12548 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12549 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12550 | EXPECT_FALSE(details.quic_broken); |
| 12551 | } |
| 12552 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12553 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12554 | HttpRequestInfo request; |
| 12555 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12556 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12557 | request.traffic_annotation = |
| 12558 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12559 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12560 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12561 | StaticSocketDataProvider first_data; |
| 12562 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12563 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12564 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12565 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12566 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12567 | |
| 12568 | MockRead data_reads[] = { |
| 12569 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12570 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12571 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12572 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12573 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12574 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12575 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12576 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12577 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12578 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12579 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12580 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12581 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 12582 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12583 | // Port is ignored by MockConnect anyway. |
| 12584 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12585 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12586 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12587 | http_server_properties->SetHttp2AlternativeService( |
| 12588 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12589 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12590 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12591 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12592 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12593 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12594 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12595 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12596 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12597 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12598 | ASSERT_TRUE(response); |
| 12599 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12600 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12601 | |
| 12602 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12603 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12604 | EXPECT_EQ("hello world", response_data); |
| 12605 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12606 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 12607 | http_server_properties->GetAlternativeServiceInfos(server); |
| 12608 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 12609 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12610 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12611 | EXPECT_TRUE( |
| 12612 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12613 | } |
| 12614 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12615 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12616 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12617 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12618 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12619 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12620 | HttpRequestInfo restricted_port_request; |
| 12621 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12622 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12623 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12624 | restricted_port_request.traffic_annotation = |
| 12625 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12626 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12627 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12628 | StaticSocketDataProvider first_data; |
| 12629 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12630 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12631 | |
| 12632 | MockRead data_reads[] = { |
| 12633 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12634 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12635 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12636 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12637 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12638 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12639 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12640 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12641 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12642 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12643 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12644 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12645 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12646 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12647 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12648 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12649 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12650 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12651 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12652 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12653 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12654 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12655 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12656 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12657 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12658 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12659 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12660 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12661 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12662 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12663 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12664 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12665 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 12666 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 12667 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12668 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12669 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12670 | |
| 12671 | HttpRequestInfo restricted_port_request; |
| 12672 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12673 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12674 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12675 | restricted_port_request.traffic_annotation = |
| 12676 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12677 | |
| 12678 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12679 | StaticSocketDataProvider first_data; |
| 12680 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12681 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12682 | |
| 12683 | MockRead data_reads[] = { |
| 12684 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12685 | MockRead("hello world"), |
| 12686 | MockRead(ASYNC, OK), |
| 12687 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12688 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12689 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12690 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12691 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12692 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12693 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12694 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12695 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12696 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12697 | session->http_server_properties(); |
| 12698 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12699 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12700 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12701 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12702 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12703 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12704 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12705 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12706 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12707 | TestCompletionCallback callback; |
| 12708 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12709 | EXPECT_EQ(ERR_IO_PENDING, |
| 12710 | trans.Start(&restricted_port_request, callback.callback(), |
| 12711 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12712 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12713 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12714 | } |
| 12715 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12716 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12717 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12718 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12719 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12720 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12721 | HttpRequestInfo restricted_port_request; |
| 12722 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12723 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12724 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12725 | restricted_port_request.traffic_annotation = |
| 12726 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12727 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12728 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12729 | StaticSocketDataProvider first_data; |
| 12730 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12731 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12732 | |
| 12733 | MockRead data_reads[] = { |
| 12734 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12735 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12736 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12737 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12738 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12739 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12740 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12741 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12742 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12743 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12744 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12745 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12746 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12747 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12748 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12749 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12750 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12751 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12752 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12753 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12754 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12755 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12756 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12757 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12758 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12759 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12760 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12761 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12762 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12763 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12764 | } |
| 12765 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12766 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12767 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12768 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12769 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12770 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12771 | HttpRequestInfo unrestricted_port_request; |
| 12772 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12773 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12774 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12775 | unrestricted_port_request.traffic_annotation = |
| 12776 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12777 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12778 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12779 | StaticSocketDataProvider first_data; |
| 12780 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12781 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12782 | |
| 12783 | MockRead data_reads[] = { |
| 12784 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12785 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12786 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12787 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12788 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12789 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12790 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12791 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12792 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12793 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12794 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12795 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12796 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12797 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12798 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12799 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12800 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12801 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12802 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12803 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12804 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12805 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12806 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12807 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12808 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12809 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12810 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12811 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12812 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12813 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12814 | } |
| 12815 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12816 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12817 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12818 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12819 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12820 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12821 | HttpRequestInfo unrestricted_port_request; |
| 12822 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12823 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12824 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12825 | unrestricted_port_request.traffic_annotation = |
| 12826 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12827 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12828 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12829 | StaticSocketDataProvider first_data; |
| 12830 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12831 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12832 | |
| 12833 | MockRead data_reads[] = { |
| 12834 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12835 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12836 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12837 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12838 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12839 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12840 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12841 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12842 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12843 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12844 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12845 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12846 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12847 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 12848 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12849 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12850 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12851 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12852 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12853 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12854 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12855 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12856 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12857 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12858 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12859 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12860 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12861 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12862 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12863 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12864 | } |
| 12865 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12866 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
Xida Chen | 9bfe0b6 | 2018-04-24 19:52:21 | [diff] [blame] | 12867 | // to an unsafe port, and that we resume the second HttpStreamFactory::Job once |
| 12868 | // the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12869 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12870 | HttpRequestInfo request; |
| 12871 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12872 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12873 | request.traffic_annotation = |
| 12874 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12875 | |
| 12876 | // The alternate protocol request will error out before we attempt to connect, |
| 12877 | // so only the standard HTTP request will try to connect. |
| 12878 | MockRead data_reads[] = { |
| 12879 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12880 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12881 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12882 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12883 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12884 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12885 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12886 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12887 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12888 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12889 | session->http_server_properties(); |
| 12890 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12891 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12892 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12893 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12894 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12895 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12896 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12897 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12898 | TestCompletionCallback callback; |
| 12899 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12900 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12901 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12902 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12903 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12904 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12905 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12906 | ASSERT_TRUE(response); |
| 12907 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12908 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12909 | |
| 12910 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12911 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12912 | EXPECT_EQ("hello world", response_data); |
| 12913 | } |
| 12914 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12915 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12916 | HttpRequestInfo request; |
| 12917 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12918 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12919 | request.traffic_annotation = |
| 12920 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12921 | |
| 12922 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12923 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12924 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12925 | MockRead("\r\n"), |
| 12926 | MockRead("hello world"), |
| 12927 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12928 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12929 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12930 | StaticSocketDataProvider first_transaction(data_reads, |
| 12931 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12932 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12933 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12934 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12935 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12936 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12937 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12938 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12939 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12940 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12941 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12942 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 12943 | spdy::SpdySerializedFrame resp( |
| 12944 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12945 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12946 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12947 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12948 | }; |
| 12949 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12950 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12951 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12952 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12953 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12954 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12955 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 12956 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12957 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12958 | &hanging_non_alternate_protocol_socket); |
| 12959 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12960 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12961 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12962 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12963 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12964 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12965 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12966 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12967 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12968 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12969 | |
| 12970 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12971 | ASSERT_TRUE(response); |
| 12972 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12973 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12974 | |
| 12975 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12976 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12977 | EXPECT_EQ("hello world", response_data); |
| 12978 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12979 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12980 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12981 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12982 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12983 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12984 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12985 | |
| 12986 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12987 | ASSERT_TRUE(response); |
| 12988 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12989 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12990 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12991 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12992 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12993 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12994 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12995 | } |
| 12996 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12997 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12998 | HttpRequestInfo request; |
| 12999 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13000 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13001 | request.traffic_annotation = |
| 13002 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13003 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13004 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13005 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13006 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13007 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13008 | MockRead("\r\n"), |
| 13009 | MockRead("hello world"), |
| 13010 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13011 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13012 | }; |
| 13013 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13014 | StaticSocketDataProvider http11_data(data_reads, base::span<MockWrite>()); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13015 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13016 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13017 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 13018 | ssl_http11.ssl_info.cert = |
| 13019 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 13020 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13021 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 13022 | |
| 13023 | // Second transaction starts an alternative and a non-alternative Job. |
| 13024 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13025 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13026 | StaticSocketDataProvider hanging_socket1; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13027 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13028 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 13029 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13030 | StaticSocketDataProvider hanging_socket2; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13031 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 13032 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13033 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13034 | // Third transaction starts an alternative and a non-alternative job. |
| 13035 | // The non-alternative job hangs, but the alternative one succeeds. |
| 13036 | // The second transaction, still pending, binds to this socket. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13037 | spdy::SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13038 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13039 | spdy::SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13040 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13041 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13042 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13043 | }; |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13044 | spdy::SpdySerializedFrame resp1( |
| 13045 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13046 | spdy::SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13047 | spdy::SpdySerializedFrame resp2( |
| 13048 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13049 | spdy::SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13050 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13051 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 13052 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13053 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13054 | }; |
| 13055 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13056 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13057 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13058 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13059 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13060 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13061 | StaticSocketDataProvider hanging_socket3; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13062 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 13063 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13064 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13065 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13066 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13067 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13068 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13069 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13070 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13071 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13072 | |
| 13073 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13074 | ASSERT_TRUE(response); |
| 13075 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13076 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13077 | |
| 13078 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13079 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13080 | EXPECT_EQ("hello world", response_data); |
| 13081 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13082 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13083 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13084 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13085 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13086 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13087 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13088 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13089 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13090 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13091 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13092 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 13093 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13094 | |
| 13095 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13096 | ASSERT_TRUE(response); |
| 13097 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13098 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13099 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13100 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13101 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13102 | EXPECT_EQ("hello!", response_data); |
| 13103 | |
| 13104 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13105 | ASSERT_TRUE(response); |
| 13106 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13107 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13108 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13109 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13110 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13111 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13112 | } |
| 13113 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13114 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
Bence Béky | bcae3709 | 2018-06-12 04:18:53 | [diff] [blame] | 13115 | session_deps_.host_resolver->set_synchronous_mode(true); |
| 13116 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13117 | HttpRequestInfo request; |
| 13118 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13119 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13120 | request.traffic_annotation = |
| 13121 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13122 | |
| 13123 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13124 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13125 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13126 | MockRead("\r\n"), |
| 13127 | MockRead("hello world"), |
| 13128 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13129 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13130 | }; |
| 13131 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13132 | StaticSocketDataProvider first_transaction(data_reads, |
| 13133 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13134 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13135 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13136 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 13137 | ssl.ssl_info.cert = |
| 13138 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 13139 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13140 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13141 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13142 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13143 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13144 | hanging_alternate_protocol_socket.set_connect_data( |
| 13145 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13146 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13147 | &hanging_alternate_protocol_socket); |
| 13148 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13149 | // 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] | 13150 | StaticSocketDataProvider second_transaction(data_reads, |
| 13151 | base::span<MockWrite>()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13152 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13153 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13154 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13155 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13156 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13157 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13158 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13159 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13160 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13161 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13162 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13163 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13164 | |
| 13165 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13166 | ASSERT_TRUE(response); |
| 13167 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13168 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13169 | |
| 13170 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13171 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13172 | EXPECT_EQ("hello world", response_data); |
| 13173 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13174 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13175 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13176 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13177 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13178 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13179 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13180 | |
| 13181 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13182 | ASSERT_TRUE(response); |
| 13183 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13184 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13185 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13186 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13187 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13188 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13189 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13190 | } |
| 13191 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13192 | // Test that proxy is resolved using the origin url, |
| 13193 | // regardless of the alternative server. |
| 13194 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 13195 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 13196 | ProxyConfig proxy_config; |
| 13197 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 13198 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13199 | auto proxy_config_service = std::make_unique<ProxyConfigServiceFixed>( |
| 13200 | ProxyConfigWithAnnotation(proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13201 | |
| 13202 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13203 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13204 | &capturing_proxy_resolver); |
| 13205 | |
| 13206 | TestNetLog net_log; |
| 13207 | |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 13208 | session_deps_.proxy_resolution_service = |
| 13209 | std::make_unique<ProxyResolutionService>( |
| 13210 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 13211 | &net_log); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13212 | |
| 13213 | session_deps_.net_log = &net_log; |
| 13214 | |
| 13215 | // Configure alternative service with a hostname that is not bypassed by the |
| 13216 | // proxy. |
| 13217 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13218 | HttpServerProperties* http_server_properties = |
| 13219 | session->http_server_properties(); |
| 13220 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13221 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13222 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13223 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13224 | http_server_properties->SetHttp2AlternativeService( |
| 13225 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13226 | |
| 13227 | // Non-alternative job should hang. |
| 13228 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13229 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13230 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 13231 | session_deps_.socket_factory->AddSocketDataProvider( |
| 13232 | &hanging_alternate_protocol_socket); |
| 13233 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13234 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13235 | |
| 13236 | HttpRequestInfo request; |
| 13237 | request.method = "GET"; |
| 13238 | request.url = GURL("https://www.example.org/"); |
| 13239 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13240 | request.traffic_annotation = |
| 13241 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13242 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13243 | spdy::SpdySerializedFrame req( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13244 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 13245 | |
| 13246 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 13247 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13248 | spdy::SpdySerializedFrame resp( |
| 13249 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13250 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13251 | MockRead spdy_reads[] = { |
| 13252 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 13253 | }; |
| 13254 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13255 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13256 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 13257 | |
| 13258 | TestCompletionCallback callback; |
| 13259 | |
| 13260 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13261 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13262 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13263 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 13264 | |
| 13265 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 13266 | ASSERT_TRUE(response); |
| 13267 | ASSERT_TRUE(response->headers); |
| 13268 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13269 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13270 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13271 | |
| 13272 | std::string response_data; |
| 13273 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 13274 | EXPECT_EQ("hello!", response_data); |
| 13275 | |
| 13276 | // Origin host bypasses proxy, no resolution should have happened. |
| 13277 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 13278 | } |
| 13279 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13280 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13281 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13282 | proxy_config.set_auto_detect(true); |
| 13283 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 13284 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13285 | CapturingProxyResolver capturing_proxy_resolver; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13286 | session_deps_.proxy_resolution_service = |
| 13287 | std::make_unique<ProxyResolutionService>( |
| 13288 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 13289 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 13290 | std::make_unique<CapturingProxyResolverFactory>( |
| 13291 | &capturing_proxy_resolver), |
| 13292 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13293 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13294 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13295 | |
| 13296 | HttpRequestInfo request; |
| 13297 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13298 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13299 | request.traffic_annotation = |
| 13300 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13301 | |
| 13302 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13303 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13304 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13305 | MockRead("\r\n"), |
| 13306 | MockRead("hello world"), |
| 13307 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13308 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13309 | }; |
| 13310 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13311 | StaticSocketDataProvider first_transaction(data_reads, |
| 13312 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13313 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13314 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13315 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13316 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13317 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13318 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13319 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13320 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13321 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13322 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13323 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13324 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13325 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13326 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13327 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13328 | }; |
| 13329 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13330 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 13331 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13332 | spdy::SpdySerializedFrame resp( |
| 13333 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13334 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13335 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13336 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 13337 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13338 | }; |
| 13339 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13340 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13341 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13342 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13343 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13344 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13345 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 13346 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13347 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13348 | &hanging_non_alternate_protocol_socket); |
| 13349 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13350 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13351 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13352 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13353 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13354 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13355 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13356 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13357 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13358 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 13359 | |
| 13360 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13361 | ASSERT_TRUE(response); |
| 13362 | ASSERT_TRUE(response->headers); |
| 13363 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 13364 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13365 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13366 | |
| 13367 | std::string response_data; |
| 13368 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 13369 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13370 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13371 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13372 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13373 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13374 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13375 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13376 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13377 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13378 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13379 | ASSERT_TRUE(response); |
| 13380 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13381 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13382 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13383 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13384 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13385 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13386 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13387 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 13388 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13389 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13390 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13391 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13392 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13393 | LoadTimingInfo load_timing_info; |
| 13394 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 13395 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13396 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13397 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13398 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13399 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 13400 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13401 | HttpRequestInfo request; |
| 13402 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13403 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13404 | request.traffic_annotation = |
| 13405 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13406 | |
| 13407 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13408 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13409 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13410 | MockRead("\r\n"), |
| 13411 | MockRead("hello world"), |
| 13412 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13413 | }; |
| 13414 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13415 | StaticSocketDataProvider first_transaction(data_reads, |
| 13416 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13417 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13418 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13419 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13420 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13421 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13422 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13423 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13424 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13425 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13426 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13427 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13428 | spdy::SpdySerializedFrame resp( |
| 13429 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13430 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13431 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13432 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13433 | }; |
| 13434 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13435 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13436 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13437 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 13438 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13439 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13440 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13441 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13442 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13443 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13444 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13445 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13446 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13447 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13448 | |
| 13449 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13450 | ASSERT_TRUE(response); |
| 13451 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13452 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13453 | |
| 13454 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13455 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13456 | EXPECT_EQ("hello world", response_data); |
| 13457 | |
| 13458 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13459 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13460 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 13461 | PRIVACY_MODE_DISABLED, |
| 13462 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13463 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 13464 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 13465 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13466 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13467 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13468 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13469 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13470 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13471 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13472 | |
| 13473 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13474 | ASSERT_TRUE(response); |
| 13475 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13476 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13477 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13478 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13479 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13480 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13481 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13482 | } |
| 13483 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13484 | // GenerateAuthToken is a mighty big test. |
| 13485 | // It tests all permutation of GenerateAuthToken behavior: |
| 13486 | // - Synchronous and Asynchronous completion. |
| 13487 | // - OK or error on completion. |
| 13488 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 13489 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 13490 | // - Non-authenticating and authenticating backend. |
| 13491 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 13492 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13493 | // problems generating an auth token for an authenticating proxy, we don't |
| 13494 | // need to test all permutations of the backend server). |
| 13495 | // |
| 13496 | // The test proceeds by going over each of the configuration cases, and |
| 13497 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 13498 | // specifies both the configuration for the test as well as the expectations |
| 13499 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13500 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13501 | static const char kServer[] = "http://www.example.com"; |
| 13502 | static const char kSecureServer[] = "https://www.example.com"; |
| 13503 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13504 | |
| 13505 | enum AuthTiming { |
| 13506 | AUTH_NONE, |
| 13507 | AUTH_SYNC, |
| 13508 | AUTH_ASYNC, |
| 13509 | }; |
| 13510 | |
| 13511 | const MockWrite kGet( |
| 13512 | "GET / HTTP/1.1\r\n" |
| 13513 | "Host: www.example.com\r\n" |
| 13514 | "Connection: keep-alive\r\n\r\n"); |
| 13515 | const MockWrite kGetProxy( |
| 13516 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13517 | "Host: www.example.com\r\n" |
| 13518 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13519 | const MockWrite kGetAuth( |
| 13520 | "GET / HTTP/1.1\r\n" |
| 13521 | "Host: www.example.com\r\n" |
| 13522 | "Connection: keep-alive\r\n" |
| 13523 | "Authorization: auth_token\r\n\r\n"); |
| 13524 | const MockWrite kGetProxyAuth( |
| 13525 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13526 | "Host: www.example.com\r\n" |
| 13527 | "Proxy-Connection: keep-alive\r\n" |
| 13528 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13529 | const MockWrite kGetAuthThroughProxy( |
| 13530 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13531 | "Host: www.example.com\r\n" |
| 13532 | "Proxy-Connection: keep-alive\r\n" |
| 13533 | "Authorization: auth_token\r\n\r\n"); |
| 13534 | const MockWrite kGetAuthWithProxyAuth( |
| 13535 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13536 | "Host: www.example.com\r\n" |
| 13537 | "Proxy-Connection: keep-alive\r\n" |
| 13538 | "Proxy-Authorization: auth_token\r\n" |
| 13539 | "Authorization: auth_token\r\n\r\n"); |
| 13540 | const MockWrite kConnect( |
| 13541 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13542 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13543 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13544 | const MockWrite kConnectProxyAuth( |
| 13545 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13546 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13547 | "Proxy-Connection: keep-alive\r\n" |
| 13548 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13549 | |
| 13550 | const MockRead kSuccess( |
| 13551 | "HTTP/1.1 200 OK\r\n" |
| 13552 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13553 | "Content-Length: 3\r\n\r\n" |
| 13554 | "Yes"); |
| 13555 | const MockRead kFailure( |
| 13556 | "Should not be called."); |
| 13557 | const MockRead kServerChallenge( |
| 13558 | "HTTP/1.1 401 Unauthorized\r\n" |
| 13559 | "WWW-Authenticate: Mock realm=server\r\n" |
| 13560 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13561 | "Content-Length: 14\r\n\r\n" |
| 13562 | "Unauthorized\r\n"); |
| 13563 | const MockRead kProxyChallenge( |
| 13564 | "HTTP/1.1 407 Unauthorized\r\n" |
| 13565 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 13566 | "Proxy-Connection: close\r\n" |
| 13567 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13568 | "Content-Length: 14\r\n\r\n" |
| 13569 | "Unauthorized\r\n"); |
| 13570 | const MockRead kProxyConnected( |
| 13571 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 13572 | |
| 13573 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 13574 | // no constructors, but the C++ compiler on Windows warns about |
| 13575 | // unspecified data in compound literals. So, moved to using constructors, |
| 13576 | // and TestRound's created with the default constructor should not be used. |
| 13577 | struct TestRound { |
| 13578 | TestRound() |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13579 | : expected_rv(ERR_UNEXPECTED), |
| 13580 | extra_write(nullptr), |
| 13581 | extra_read(nullptr) {} |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 13582 | TestRound(const MockWrite& write_arg, |
| 13583 | const MockRead& read_arg, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13584 | int expected_rv_arg) |
| 13585 | : write(write_arg), |
| 13586 | read(read_arg), |
| 13587 | expected_rv(expected_rv_arg), |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13588 | extra_write(nullptr), |
| 13589 | extra_read(nullptr) {} |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13590 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 13591 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 13592 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13593 | : write(write_arg), |
| 13594 | read(read_arg), |
| 13595 | expected_rv(expected_rv_arg), |
| 13596 | extra_write(extra_write_arg), |
| 13597 | extra_read(extra_read_arg) { |
| 13598 | } |
| 13599 | MockWrite write; |
| 13600 | MockRead read; |
| 13601 | int expected_rv; |
| 13602 | const MockWrite* extra_write; |
| 13603 | const MockRead* extra_read; |
| 13604 | }; |
| 13605 | |
| 13606 | static const int kNoSSL = 500; |
| 13607 | |
| 13608 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13609 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13610 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13611 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13612 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13613 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13614 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13615 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13616 | int num_auth_rounds; |
| 13617 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13618 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13619 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13620 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13621 | {__LINE__, |
| 13622 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13623 | AUTH_NONE, |
| 13624 | OK, |
| 13625 | kServer, |
| 13626 | AUTH_NONE, |
| 13627 | OK, |
| 13628 | 1, |
| 13629 | kNoSSL, |
| 13630 | {TestRound(kGet, kSuccess, OK)}}, |
| 13631 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13632 | {__LINE__, |
| 13633 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13634 | AUTH_NONE, |
| 13635 | OK, |
| 13636 | kServer, |
| 13637 | AUTH_SYNC, |
| 13638 | OK, |
| 13639 | 2, |
| 13640 | kNoSSL, |
| 13641 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13642 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13643 | {__LINE__, |
| 13644 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13645 | AUTH_NONE, |
| 13646 | OK, |
| 13647 | kServer, |
| 13648 | AUTH_SYNC, |
| 13649 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13650 | 3, |
| 13651 | kNoSSL, |
| 13652 | {TestRound(kGet, kServerChallenge, OK), |
| 13653 | TestRound(kGet, kServerChallenge, OK), |
| 13654 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13655 | {__LINE__, |
| 13656 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13657 | AUTH_NONE, |
| 13658 | OK, |
| 13659 | kServer, |
| 13660 | AUTH_SYNC, |
| 13661 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 13662 | 2, |
| 13663 | kNoSSL, |
| 13664 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13665 | {__LINE__, |
| 13666 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13667 | AUTH_NONE, |
| 13668 | OK, |
| 13669 | kServer, |
| 13670 | AUTH_SYNC, |
| 13671 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 13672 | 2, |
| 13673 | kNoSSL, |
| 13674 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13675 | {__LINE__, |
| 13676 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13677 | AUTH_SYNC, |
| 13678 | ERR_FAILED, |
| 13679 | kServer, |
| 13680 | AUTH_NONE, |
| 13681 | OK, |
| 13682 | 2, |
| 13683 | kNoSSL, |
| 13684 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13685 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13686 | {__LINE__, |
| 13687 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13688 | AUTH_ASYNC, |
| 13689 | ERR_FAILED, |
| 13690 | kServer, |
| 13691 | AUTH_NONE, |
| 13692 | OK, |
| 13693 | 2, |
| 13694 | kNoSSL, |
| 13695 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13696 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13697 | {__LINE__, |
| 13698 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13699 | AUTH_NONE, |
| 13700 | OK, |
| 13701 | kServer, |
| 13702 | AUTH_SYNC, |
| 13703 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13704 | 2, |
| 13705 | kNoSSL, |
| 13706 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13707 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13708 | {__LINE__, |
| 13709 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13710 | AUTH_NONE, |
| 13711 | OK, |
| 13712 | kServer, |
| 13713 | AUTH_ASYNC, |
| 13714 | ERR_FAILED, |
| 13715 | 2, |
| 13716 | kNoSSL, |
| 13717 | {TestRound(kGet, kServerChallenge, OK), |
| 13718 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13719 | {__LINE__, |
| 13720 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13721 | AUTH_NONE, |
| 13722 | OK, |
| 13723 | kServer, |
| 13724 | AUTH_ASYNC, |
| 13725 | OK, |
| 13726 | 2, |
| 13727 | kNoSSL, |
| 13728 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13729 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13730 | {__LINE__, |
| 13731 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13732 | AUTH_NONE, |
| 13733 | OK, |
| 13734 | kServer, |
| 13735 | AUTH_ASYNC, |
| 13736 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13737 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13738 | kNoSSL, |
| 13739 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13740 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 13741 | TestRound(kGet, kServerChallenge, OK), |
| 13742 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13743 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13744 | {__LINE__, |
| 13745 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13746 | AUTH_NONE, |
| 13747 | OK, |
| 13748 | kServer, |
| 13749 | AUTH_NONE, |
| 13750 | OK, |
| 13751 | 1, |
| 13752 | kNoSSL, |
| 13753 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 13754 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13755 | {__LINE__, |
| 13756 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13757 | AUTH_NONE, |
| 13758 | OK, |
| 13759 | kServer, |
| 13760 | AUTH_SYNC, |
| 13761 | OK, |
| 13762 | 2, |
| 13763 | kNoSSL, |
| 13764 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13765 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13766 | {__LINE__, |
| 13767 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13768 | AUTH_NONE, |
| 13769 | OK, |
| 13770 | kServer, |
| 13771 | AUTH_SYNC, |
| 13772 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13773 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13774 | kNoSSL, |
| 13775 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13776 | TestRound(kGetProxy, kServerChallenge, OK), |
| 13777 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13778 | {__LINE__, |
| 13779 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13780 | AUTH_NONE, |
| 13781 | OK, |
| 13782 | kServer, |
| 13783 | AUTH_ASYNC, |
| 13784 | OK, |
| 13785 | 2, |
| 13786 | kNoSSL, |
| 13787 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13788 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13789 | {__LINE__, |
| 13790 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13791 | AUTH_NONE, |
| 13792 | OK, |
| 13793 | kServer, |
| 13794 | AUTH_ASYNC, |
| 13795 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13796 | 2, |
| 13797 | kNoSSL, |
| 13798 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13799 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13800 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13801 | {__LINE__, |
| 13802 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13803 | AUTH_SYNC, |
| 13804 | OK, |
| 13805 | kServer, |
| 13806 | AUTH_NONE, |
| 13807 | OK, |
| 13808 | 2, |
| 13809 | kNoSSL, |
| 13810 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13811 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13812 | {__LINE__, |
| 13813 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13814 | AUTH_SYNC, |
| 13815 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13816 | kServer, |
| 13817 | AUTH_NONE, |
| 13818 | OK, |
| 13819 | 2, |
| 13820 | kNoSSL, |
| 13821 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13822 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13823 | {__LINE__, |
| 13824 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13825 | AUTH_ASYNC, |
| 13826 | OK, |
| 13827 | kServer, |
| 13828 | AUTH_NONE, |
| 13829 | OK, |
| 13830 | 2, |
| 13831 | kNoSSL, |
| 13832 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13833 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13834 | {__LINE__, |
| 13835 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13836 | AUTH_ASYNC, |
| 13837 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13838 | kServer, |
| 13839 | AUTH_NONE, |
| 13840 | OK, |
| 13841 | 2, |
| 13842 | kNoSSL, |
| 13843 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13844 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13845 | {__LINE__, |
| 13846 | kProxy, |
| 13847 | AUTH_ASYNC, |
| 13848 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13849 | kServer, |
| 13850 | AUTH_NONE, |
| 13851 | OK, |
| 13852 | 3, |
| 13853 | kNoSSL, |
| 13854 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13855 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13856 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13857 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13858 | {__LINE__, |
| 13859 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13860 | AUTH_SYNC, |
| 13861 | OK, |
| 13862 | kServer, |
| 13863 | AUTH_SYNC, |
| 13864 | OK, |
| 13865 | 3, |
| 13866 | kNoSSL, |
| 13867 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13868 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13869 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13870 | {__LINE__, |
| 13871 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13872 | AUTH_SYNC, |
| 13873 | OK, |
| 13874 | kServer, |
| 13875 | AUTH_SYNC, |
| 13876 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13877 | 3, |
| 13878 | kNoSSL, |
| 13879 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13880 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13881 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13882 | {__LINE__, |
| 13883 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13884 | AUTH_ASYNC, |
| 13885 | OK, |
| 13886 | kServer, |
| 13887 | AUTH_SYNC, |
| 13888 | OK, |
| 13889 | 3, |
| 13890 | kNoSSL, |
| 13891 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13892 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13893 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13894 | {__LINE__, |
| 13895 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13896 | AUTH_ASYNC, |
| 13897 | OK, |
| 13898 | kServer, |
| 13899 | AUTH_SYNC, |
| 13900 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13901 | 3, |
| 13902 | kNoSSL, |
| 13903 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13904 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13905 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13906 | {__LINE__, |
| 13907 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13908 | AUTH_SYNC, |
| 13909 | OK, |
| 13910 | kServer, |
| 13911 | AUTH_ASYNC, |
| 13912 | OK, |
| 13913 | 3, |
| 13914 | kNoSSL, |
| 13915 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13916 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13917 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13918 | {__LINE__, |
| 13919 | kProxy, |
| 13920 | AUTH_SYNC, |
| 13921 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13922 | kServer, |
| 13923 | AUTH_ASYNC, |
| 13924 | OK, |
| 13925 | 4, |
| 13926 | kNoSSL, |
| 13927 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13928 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13929 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13930 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 13931 | {__LINE__, |
| 13932 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13933 | AUTH_SYNC, |
| 13934 | OK, |
| 13935 | kServer, |
| 13936 | AUTH_ASYNC, |
| 13937 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13938 | 3, |
| 13939 | kNoSSL, |
| 13940 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13941 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13942 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13943 | {__LINE__, |
| 13944 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13945 | AUTH_ASYNC, |
| 13946 | OK, |
| 13947 | kServer, |
| 13948 | AUTH_ASYNC, |
| 13949 | OK, |
| 13950 | 3, |
| 13951 | kNoSSL, |
| 13952 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13953 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13954 | TestRound(kGetAuthWithProxyAuth, 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_ASYNC, |
| 13958 | OK, |
| 13959 | kServer, |
| 13960 | AUTH_ASYNC, |
| 13961 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13962 | 3, |
| 13963 | kNoSSL, |
| 13964 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13965 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13966 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13967 | {__LINE__, |
| 13968 | kProxy, |
| 13969 | AUTH_ASYNC, |
| 13970 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13971 | kServer, |
| 13972 | AUTH_ASYNC, |
| 13973 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13974 | 4, |
| 13975 | kNoSSL, |
| 13976 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13977 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13978 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13979 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13980 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13981 | {__LINE__, |
| 13982 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13983 | AUTH_NONE, |
| 13984 | OK, |
| 13985 | kSecureServer, |
| 13986 | AUTH_NONE, |
| 13987 | OK, |
| 13988 | 1, |
| 13989 | 0, |
| 13990 | {TestRound(kGet, kSuccess, OK)}}, |
| 13991 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13992 | {__LINE__, |
| 13993 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13994 | AUTH_NONE, |
| 13995 | OK, |
| 13996 | kSecureServer, |
| 13997 | AUTH_SYNC, |
| 13998 | OK, |
| 13999 | 2, |
| 14000 | 0, |
| 14001 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14002 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14003 | {__LINE__, |
| 14004 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14005 | AUTH_NONE, |
| 14006 | OK, |
| 14007 | kSecureServer, |
| 14008 | AUTH_SYNC, |
| 14009 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14010 | 2, |
| 14011 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14012 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14013 | {__LINE__, |
| 14014 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14015 | AUTH_NONE, |
| 14016 | OK, |
| 14017 | kSecureServer, |
| 14018 | AUTH_ASYNC, |
| 14019 | OK, |
| 14020 | 2, |
| 14021 | 0, |
| 14022 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14023 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14024 | {__LINE__, |
| 14025 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14026 | AUTH_NONE, |
| 14027 | OK, |
| 14028 | kSecureServer, |
| 14029 | AUTH_ASYNC, |
| 14030 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14031 | 2, |
| 14032 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14033 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14034 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14035 | {__LINE__, |
| 14036 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14037 | AUTH_NONE, |
| 14038 | OK, |
| 14039 | kSecureServer, |
| 14040 | AUTH_NONE, |
| 14041 | OK, |
| 14042 | 1, |
| 14043 | 0, |
| 14044 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 14045 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14046 | {__LINE__, |
| 14047 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14048 | AUTH_NONE, |
| 14049 | OK, |
| 14050 | kSecureServer, |
| 14051 | AUTH_SYNC, |
| 14052 | OK, |
| 14053 | 2, |
| 14054 | 0, |
| 14055 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14056 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14057 | {__LINE__, |
| 14058 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14059 | AUTH_NONE, |
| 14060 | OK, |
| 14061 | kSecureServer, |
| 14062 | AUTH_SYNC, |
| 14063 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14064 | 2, |
| 14065 | 0, |
| 14066 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14067 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14068 | {__LINE__, |
| 14069 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14070 | AUTH_NONE, |
| 14071 | OK, |
| 14072 | kSecureServer, |
| 14073 | AUTH_ASYNC, |
| 14074 | OK, |
| 14075 | 2, |
| 14076 | 0, |
| 14077 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14078 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14079 | {__LINE__, |
| 14080 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14081 | AUTH_NONE, |
| 14082 | OK, |
| 14083 | kSecureServer, |
| 14084 | AUTH_ASYNC, |
| 14085 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14086 | 2, |
| 14087 | 0, |
| 14088 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14089 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14090 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14091 | {__LINE__, |
| 14092 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14093 | AUTH_SYNC, |
| 14094 | OK, |
| 14095 | kSecureServer, |
| 14096 | AUTH_NONE, |
| 14097 | OK, |
| 14098 | 2, |
| 14099 | 1, |
| 14100 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14101 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14102 | {__LINE__, |
| 14103 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14104 | AUTH_SYNC, |
| 14105 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14106 | kSecureServer, |
| 14107 | AUTH_NONE, |
| 14108 | OK, |
| 14109 | 2, |
| 14110 | kNoSSL, |
| 14111 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14112 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14113 | {__LINE__, |
| 14114 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14115 | AUTH_SYNC, |
| 14116 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 14117 | kSecureServer, |
| 14118 | AUTH_NONE, |
| 14119 | OK, |
| 14120 | 2, |
| 14121 | kNoSSL, |
| 14122 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14123 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14124 | {__LINE__, |
| 14125 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14126 | AUTH_SYNC, |
| 14127 | ERR_UNEXPECTED, |
| 14128 | kSecureServer, |
| 14129 | AUTH_NONE, |
| 14130 | OK, |
| 14131 | 2, |
| 14132 | kNoSSL, |
| 14133 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14134 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14135 | {__LINE__, |
| 14136 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14137 | AUTH_ASYNC, |
| 14138 | OK, |
| 14139 | kSecureServer, |
| 14140 | AUTH_NONE, |
| 14141 | OK, |
| 14142 | 2, |
| 14143 | 1, |
| 14144 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14145 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14146 | {__LINE__, |
| 14147 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14148 | AUTH_ASYNC, |
| 14149 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14150 | kSecureServer, |
| 14151 | AUTH_NONE, |
| 14152 | OK, |
| 14153 | 2, |
| 14154 | kNoSSL, |
| 14155 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14156 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14157 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14158 | {__LINE__, |
| 14159 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14160 | AUTH_SYNC, |
| 14161 | OK, |
| 14162 | kSecureServer, |
| 14163 | AUTH_SYNC, |
| 14164 | OK, |
| 14165 | 3, |
| 14166 | 1, |
| 14167 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14168 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14169 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14170 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14171 | {__LINE__, |
| 14172 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14173 | AUTH_SYNC, |
| 14174 | OK, |
| 14175 | kSecureServer, |
| 14176 | AUTH_SYNC, |
| 14177 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14178 | 3, |
| 14179 | 1, |
| 14180 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14181 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14182 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14183 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14184 | {__LINE__, |
| 14185 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14186 | AUTH_ASYNC, |
| 14187 | OK, |
| 14188 | kSecureServer, |
| 14189 | AUTH_SYNC, |
| 14190 | OK, |
| 14191 | 3, |
| 14192 | 1, |
| 14193 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14194 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14195 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14196 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14197 | {__LINE__, |
| 14198 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14199 | AUTH_ASYNC, |
| 14200 | OK, |
| 14201 | kSecureServer, |
| 14202 | AUTH_SYNC, |
| 14203 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14204 | 3, |
| 14205 | 1, |
| 14206 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14207 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14208 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14209 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14210 | {__LINE__, |
| 14211 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14212 | AUTH_SYNC, |
| 14213 | OK, |
| 14214 | kSecureServer, |
| 14215 | AUTH_ASYNC, |
| 14216 | OK, |
| 14217 | 3, |
| 14218 | 1, |
| 14219 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14220 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14221 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14222 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14223 | {__LINE__, |
| 14224 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14225 | AUTH_SYNC, |
| 14226 | OK, |
| 14227 | kSecureServer, |
| 14228 | AUTH_ASYNC, |
| 14229 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14230 | 3, |
| 14231 | 1, |
| 14232 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14233 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14234 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14235 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14236 | {__LINE__, |
| 14237 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14238 | AUTH_ASYNC, |
| 14239 | OK, |
| 14240 | kSecureServer, |
| 14241 | AUTH_ASYNC, |
| 14242 | OK, |
| 14243 | 3, |
| 14244 | 1, |
| 14245 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14246 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14247 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14248 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14249 | {__LINE__, |
| 14250 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14251 | AUTH_ASYNC, |
| 14252 | OK, |
| 14253 | kSecureServer, |
| 14254 | AUTH_ASYNC, |
| 14255 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14256 | 3, |
| 14257 | 1, |
| 14258 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14259 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14260 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14261 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14262 | {__LINE__, |
| 14263 | kProxy, |
| 14264 | AUTH_ASYNC, |
| 14265 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14266 | kSecureServer, |
| 14267 | AUTH_ASYNC, |
| 14268 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14269 | 4, |
| 14270 | 2, |
| 14271 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14272 | TestRound(kConnect, kProxyChallenge, OK), |
| 14273 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14274 | &kServerChallenge), |
| 14275 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14276 | }; |
| 14277 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14278 | for (const auto& test_config : test_configs) { |
| 14279 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 14280 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14281 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14282 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14283 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14284 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14285 | |
| 14286 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14287 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14288 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14289 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14290 | std::string auth_challenge = "Mock realm=proxy"; |
| 14291 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14292 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14293 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14294 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14295 | empty_ssl_info, origin, |
| 14296 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14297 | auth_handler->SetGenerateExpectation( |
| 14298 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14299 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14300 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 14301 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14302 | } |
| 14303 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 14304 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14305 | std::string auth_challenge = "Mock realm=server"; |
| 14306 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14307 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14308 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14309 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14310 | empty_ssl_info, origin, |
| 14311 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14312 | auth_handler->SetGenerateExpectation( |
| 14313 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14314 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14315 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14316 | |
| 14317 | // The second handler always succeeds. It should only be used where there |
| 14318 | // are multiple auth sessions for server auth in the same network |
| 14319 | // transaction using the same auth scheme. |
| 14320 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14321 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14322 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 14323 | empty_ssl_info, origin, |
| 14324 | NetLogWithSource()); |
| 14325 | second_handler->SetGenerateExpectation(true, OK); |
| 14326 | auth_factory->AddMockHandler(second_handler.release(), |
| 14327 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14328 | } |
| 14329 | if (test_config.proxy_url) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14330 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14331 | ProxyResolutionService::CreateFixed(test_config.proxy_url, |
| 14332 | TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14333 | } else { |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14334 | session_deps_.proxy_resolution_service = |
| 14335 | ProxyResolutionService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14336 | } |
| 14337 | |
| 14338 | HttpRequestInfo request; |
| 14339 | request.method = "GET"; |
| 14340 | request.url = GURL(test_config.server_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14341 | request.traffic_annotation = |
| 14342 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14343 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14344 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14345 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14346 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 14347 | |
| 14348 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 14349 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14350 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14351 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14352 | const TestRound& read_write_round = test_config.rounds[round]; |
| 14353 | |
| 14354 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14355 | mock_reads.back().push_back(read_write_round.read); |
| 14356 | mock_writes.back().push_back(read_write_round.write); |
| 14357 | |
| 14358 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 14359 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 14360 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14361 | mock_reads.push_back(std::vector<MockRead>()); |
| 14362 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14363 | } |
| 14364 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14365 | if (read_write_round.extra_read) { |
| 14366 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14367 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14368 | if (read_write_round.extra_write) { |
| 14369 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 14370 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14371 | |
| 14372 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14373 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14374 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14375 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14376 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14377 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14378 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14379 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14380 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14381 | mock_reads[i], mock_writes[i])); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14382 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 14383 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14384 | } |
| 14385 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 14386 | // Transaction must be created after DataProviders, so it's destroyed before |
| 14387 | // they are as well. |
| 14388 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 14389 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14390 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14391 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14392 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14393 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14394 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14395 | int rv; |
| 14396 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14397 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14398 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14399 | rv = trans.RestartWithAuth( |
| 14400 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14401 | } |
| 14402 | if (rv == ERR_IO_PENDING) |
| 14403 | rv = callback.WaitForResult(); |
| 14404 | |
| 14405 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14406 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14407 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 14408 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14409 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 14410 | continue; |
| 14411 | } |
| 14412 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14413 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14414 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14415 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14416 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14417 | } |
| 14418 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 14419 | } |
| 14420 | } |
| 14421 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14422 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14423 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14424 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14425 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14426 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14427 | session_deps_.proxy_resolution_service = |
| 14428 | ProxyResolutionService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14429 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14430 | |
| 14431 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14432 | auth_handler->set_connection_based(true); |
| 14433 | std::string auth_challenge = "Mock realm=server"; |
| 14434 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14435 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14436 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14437 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14438 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14439 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14440 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14441 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14442 | int rv = OK; |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 14443 | const HttpResponseInfo* response = nullptr; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14444 | HttpRequestInfo request; |
| 14445 | request.method = "GET"; |
| 14446 | request.url = origin; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14447 | request.traffic_annotation = |
| 14448 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14449 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14450 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14451 | |
| 14452 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 14453 | // to validate that the TCP socket is not released to the pool between |
| 14454 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14455 | HttpNetworkSessionPeer session_peer(session.get()); |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame^] | 14456 | CommonConnectJobParams common_connect_job_params( |
| 14457 | session->CreateCommonConnectJobParams()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14458 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
Tarun Bansal | a763509 | 2019-02-20 10:00:59 | [diff] [blame] | 14459 | 50, // Max sockets for pool |
| 14460 | 1, // Max sockets per group |
| 14461 | base::TimeDelta::FromSeconds(10), // unused_idle_socket_timeout |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame^] | 14462 | &common_connect_job_params, session_deps_.ssl_config_service.get()); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14463 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 14464 | mock_pool_manager->SetSocketPool(ProxyServer::Direct(), |
| 14465 | base::WrapUnique(transport_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14466 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14467 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14468 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14469 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14470 | |
| 14471 | const MockWrite kGet( |
| 14472 | "GET / HTTP/1.1\r\n" |
| 14473 | "Host: www.example.com\r\n" |
| 14474 | "Connection: keep-alive\r\n\r\n"); |
| 14475 | const MockWrite kGetAuth( |
| 14476 | "GET / HTTP/1.1\r\n" |
| 14477 | "Host: www.example.com\r\n" |
| 14478 | "Connection: keep-alive\r\n" |
| 14479 | "Authorization: auth_token\r\n\r\n"); |
| 14480 | |
| 14481 | const MockRead kServerChallenge( |
| 14482 | "HTTP/1.1 401 Unauthorized\r\n" |
| 14483 | "WWW-Authenticate: Mock realm=server\r\n" |
| 14484 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14485 | "Content-Length: 14\r\n\r\n" |
| 14486 | "Unauthorized\r\n"); |
| 14487 | const MockRead kSuccess( |
| 14488 | "HTTP/1.1 200 OK\r\n" |
| 14489 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14490 | "Content-Length: 3\r\n\r\n" |
| 14491 | "Yes"); |
| 14492 | |
| 14493 | MockWrite writes[] = { |
| 14494 | // First round |
| 14495 | kGet, |
| 14496 | // Second round |
| 14497 | kGetAuth, |
| 14498 | // Third round |
| 14499 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14500 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14501 | kGetAuth, |
| 14502 | // Competing request |
| 14503 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14504 | }; |
| 14505 | MockRead reads[] = { |
| 14506 | // First round |
| 14507 | kServerChallenge, |
| 14508 | // Second round |
| 14509 | kServerChallenge, |
| 14510 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14511 | kServerChallenge, |
| 14512 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14513 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14514 | // Competing response |
| 14515 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14516 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14517 | StaticSocketDataProvider data_provider(reads, writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14518 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14519 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 14520 | const ClientSocketPool::GroupId kSocketGroup( |
| 14521 | HostPortPair("www.example.com", 80), ClientSocketPool::SocketType::kHttp, |
| 14522 | false /* privacy_mode */); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14523 | |
| 14524 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14525 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14526 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14527 | if (rv == ERR_IO_PENDING) |
| 14528 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14529 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14530 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14531 | ASSERT_TRUE(response); |
| 14532 | EXPECT_TRUE(response->auth_challenge); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14533 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14534 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14535 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14536 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14537 | // In between rounds, another request comes in for the same domain. |
| 14538 | // It should not be able to grab the TCP socket that trans has already |
| 14539 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14540 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14541 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14542 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 14543 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14544 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14545 | // callback_compete.WaitForResult at this point would stall forever, |
| 14546 | // since the HttpNetworkTransaction does not release the request back to |
| 14547 | // the pool until after authentication completes. |
| 14548 | |
| 14549 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14550 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14551 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14552 | if (rv == ERR_IO_PENDING) |
| 14553 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14554 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14555 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14556 | ASSERT_TRUE(response); |
| 14557 | EXPECT_FALSE(response->auth_challenge); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14558 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14559 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14560 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14561 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14562 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14563 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14564 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14565 | if (rv == ERR_IO_PENDING) |
| 14566 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14567 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14568 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14569 | ASSERT_TRUE(response); |
| 14570 | EXPECT_FALSE(response->auth_challenge); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14571 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14572 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14573 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14574 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14575 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14576 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14577 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14578 | if (rv == ERR_IO_PENDING) |
| 14579 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14580 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14581 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14582 | ASSERT_TRUE(response); |
| 14583 | EXPECT_FALSE(response->auth_challenge); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14584 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14585 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14586 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 14587 | // auth handler should transition to a DONE state in concert with the remote |
| 14588 | // server. But that's not something we can test here with a mock handler. |
| 14589 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 14590 | auth_handler->state()); |
| 14591 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14592 | // Read the body since the fourth round was successful. This will also |
| 14593 | // release the socket back to the pool. |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 14594 | scoped_refptr<IOBufferWithSize> io_buf = |
| 14595 | base::MakeRefCounted<IOBufferWithSize>(50); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14596 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14597 | if (rv == ERR_IO_PENDING) |
| 14598 | rv = callback.WaitForResult(); |
| 14599 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14600 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14601 | EXPECT_EQ(0, rv); |
| 14602 | // There are still 0 idle sockets, since the trans_compete transaction |
| 14603 | // will be handed it immediately after trans releases it to the group. |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14604 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14605 | |
| 14606 | // The competing request can now finish. Wait for the headers and then |
| 14607 | // read the body. |
| 14608 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14609 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14610 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14611 | if (rv == ERR_IO_PENDING) |
| 14612 | rv = callback.WaitForResult(); |
| 14613 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14614 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14615 | EXPECT_EQ(0, rv); |
| 14616 | |
| 14617 | // Finally, the socket is released to the group. |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14618 | EXPECT_EQ(1u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14619 | } |
| 14620 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14621 | // This tests the case that a request is issued via http instead of spdy after |
| 14622 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14623 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14624 | HttpRequestInfo request; |
| 14625 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14626 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14627 | request.traffic_annotation = |
| 14628 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14629 | |
| 14630 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14631 | MockWrite( |
| 14632 | "GET / HTTP/1.1\r\n" |
| 14633 | "Host: www.example.org\r\n" |
| 14634 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14635 | }; |
| 14636 | |
| 14637 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14638 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 14639 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14640 | MockRead("\r\n"), |
| 14641 | MockRead("hello world"), |
| 14642 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14643 | }; |
| 14644 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14645 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14646 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14647 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14648 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14649 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14650 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14651 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14652 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14653 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14654 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14655 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14656 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14657 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14658 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14659 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14660 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14661 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14662 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14663 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14664 | ASSERT_TRUE(response); |
| 14665 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14666 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14667 | |
| 14668 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14669 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14670 | EXPECT_EQ("hello world", response_data); |
| 14671 | |
| 14672 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14673 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14674 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14675 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 14676 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 14677 | // immediate server closing of the socket. |
| 14678 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14679 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14680 | HttpRequestInfo request; |
| 14681 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14682 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14683 | request.traffic_annotation = |
| 14684 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14685 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14686 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14687 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14688 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14689 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14690 | spdy::SpdySerializedFrame req( |
| 14691 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14692 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14693 | |
| 14694 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14695 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14696 | }; |
| 14697 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14698 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14699 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14700 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14701 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14702 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14703 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14704 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14705 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14706 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14707 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14708 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14709 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14710 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14711 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 14712 | // it gets it. This is needed since the auth handler may get destroyed |
| 14713 | // before we get a chance to query it. |
| 14714 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 14715 | public: |
| 14716 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 14717 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 14718 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14719 | |
| 14720 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14721 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 14722 | const HttpRequestInfo* request, |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 14723 | CompletionOnceCallback callback, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14724 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14725 | *url_ = request->url; |
| 14726 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 14727 | credentials, request, std::move(callback), auth_token); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14728 | } |
| 14729 | |
| 14730 | private: |
| 14731 | GURL* url_; |
| 14732 | }; |
| 14733 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14734 | // Test that if we cancel the transaction as the connection is completing, that |
| 14735 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14736 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14737 | // Setup everything about the connection to complete synchronously, so that |
| 14738 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 14739 | // for is the callback from the HttpStreamRequest. |
| 14740 | // Then cancel the transaction. |
| 14741 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 14742 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14743 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14744 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 14745 | MockRead(SYNCHRONOUS, "hello world"), |
| 14746 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14747 | }; |
| 14748 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14749 | HttpRequestInfo request; |
| 14750 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14751 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14752 | request.traffic_annotation = |
| 14753 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14754 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14755 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14756 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14757 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14758 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14759 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14760 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14761 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14762 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14763 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14764 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14765 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14766 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14767 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14768 | trans.reset(); // Cancel the transaction here. |
| 14769 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14770 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 14771 | } |
| 14772 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14773 | // Test that if a transaction is cancelled after receiving the headers, the |
| 14774 | // stream is drained properly and added back to the socket pool. The main |
| 14775 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 14776 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 14777 | // deleted. |
| 14778 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14779 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14780 | MockRead data_reads[] = { |
| 14781 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 14782 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 14783 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 14784 | MockRead(ASYNC, "1"), |
| 14785 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 14786 | // HttpNetworkTransaction has been deleted. |
| 14787 | MockRead(ASYNC, "2"), |
| 14788 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 14789 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14790 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14791 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14792 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14793 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14794 | |
| 14795 | { |
| 14796 | HttpRequestInfo request; |
| 14797 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14798 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14799 | request.traffic_annotation = |
| 14800 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14801 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14802 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14803 | TestCompletionCallback callback; |
| 14804 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14805 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14806 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14807 | callback.WaitForResult(); |
| 14808 | |
| 14809 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14810 | ASSERT_TRUE(response); |
| 14811 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14812 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14813 | |
| 14814 | // The transaction and HttpRequestInfo are deleted. |
| 14815 | } |
| 14816 | |
| 14817 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14818 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14819 | |
| 14820 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14821 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14822 | } |
| 14823 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14824 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14825 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14826 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14827 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14828 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14829 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14830 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14831 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14832 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14833 | HttpRequestInfo request; |
| 14834 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14835 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14836 | request.traffic_annotation = |
| 14837 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14838 | |
| 14839 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14840 | MockWrite( |
| 14841 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 14842 | "Host: www.example.org\r\n" |
| 14843 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14844 | }; |
| 14845 | |
| 14846 | MockRead data_reads1[] = { |
| 14847 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14848 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14849 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14850 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14851 | }; |
| 14852 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14853 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14854 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14855 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14856 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14857 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14858 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14859 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14860 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14861 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 14862 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14863 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14864 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14865 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14866 | |
| 14867 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14868 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14869 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14870 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14871 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14872 | |
| 14873 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14874 | EXPECT_EQ(200, response->headers->response_code()); |
| 14875 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14876 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14877 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14878 | HostPortPair::FromString("myproxy:70")), |
| 14879 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14880 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14881 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14882 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14883 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14884 | |
| 14885 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14886 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14887 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14888 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14889 | } |
| 14890 | |
| 14891 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14892 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14893 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14894 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14895 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14896 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14897 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14898 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14899 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14900 | HttpRequestInfo request; |
| 14901 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14902 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14903 | request.traffic_annotation = |
| 14904 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14905 | |
| 14906 | // Since we have proxy, should try to establish tunnel. |
| 14907 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14908 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14909 | "Host: www.example.org:443\r\n" |
| 14910 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14911 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14912 | MockWrite("GET / HTTP/1.1\r\n" |
| 14913 | "Host: www.example.org\r\n" |
| 14914 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14915 | }; |
| 14916 | |
| 14917 | MockRead data_reads1[] = { |
| 14918 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14919 | |
| 14920 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14921 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14922 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14923 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14924 | }; |
| 14925 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14926 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14927 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14928 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14929 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14930 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14931 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14932 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14933 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14934 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14935 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14936 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 14937 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14938 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14939 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14940 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14941 | |
| 14942 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14943 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14944 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14945 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14946 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14947 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14948 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14949 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14950 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14951 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14952 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14953 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14954 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14955 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14956 | |
| 14957 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14958 | EXPECT_EQ(200, response->headers->response_code()); |
| 14959 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14960 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14961 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14962 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14963 | HostPortPair::FromString("myproxy:70")), |
| 14964 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14965 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14966 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14967 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14968 | |
| 14969 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14970 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14971 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14972 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14973 | } |
| 14974 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14975 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 14976 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14977 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14978 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14979 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14980 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14981 | BoundTestNetLog log; |
| 14982 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14983 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14984 | |
| 14985 | HttpRequestInfo request; |
| 14986 | request.method = "GET"; |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14987 | request.url = GURL("https://[::2]:443/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14988 | request.traffic_annotation = |
| 14989 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14990 | |
| 14991 | // Since we have proxy, should try to establish tunnel. |
| 14992 | MockWrite data_writes1[] = { |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14993 | MockWrite("CONNECT [::2]:443 HTTP/1.1\r\n" |
| 14994 | "Host: [::2]:443\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14995 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 14996 | |
| 14997 | MockWrite("GET / HTTP/1.1\r\n" |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14998 | "Host: [::2]\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14999 | "Connection: keep-alive\r\n\r\n"), |
| 15000 | }; |
| 15001 | |
| 15002 | MockRead data_reads1[] = { |
| 15003 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15004 | |
| 15005 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15006 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 15007 | MockRead("Content-Length: 100\r\n\r\n"), |
| 15008 | MockRead(SYNCHRONOUS, OK), |
| 15009 | }; |
| 15010 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15011 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15012 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15013 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15014 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15015 | |
| 15016 | TestCompletionCallback callback1; |
| 15017 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15018 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15019 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15020 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15021 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15022 | |
| 15023 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15024 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15025 | TestNetLogEntry::List entries; |
| 15026 | log.GetEntries(&entries); |
| 15027 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15028 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 15029 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15030 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15031 | entries, pos, |
| 15032 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 15033 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15034 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15035 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15036 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15037 | |
| 15038 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 15039 | EXPECT_EQ(200, response->headers->response_code()); |
| 15040 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 15041 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 15042 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 15043 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 15044 | HostPortPair::FromString("myproxy:70")), |
| 15045 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15046 | |
| 15047 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15048 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15049 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 15050 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 15051 | } |
| 15052 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15053 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 15054 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15055 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15056 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 15057 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15058 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15059 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15060 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15061 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15062 | HttpRequestInfo request; |
| 15063 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15064 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15065 | request.traffic_annotation = |
| 15066 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15067 | |
| 15068 | // Since we have proxy, should try to establish tunnel. |
| 15069 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15070 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15071 | "Host: www.example.org:443\r\n" |
| 15072 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15073 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15074 | MockWrite("GET / HTTP/1.1\r\n" |
| 15075 | "Host: www.example.org\r\n" |
| 15076 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15077 | }; |
| 15078 | |
| 15079 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15080 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15081 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15082 | }; |
| 15083 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15084 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15085 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15086 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15087 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15088 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15089 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15090 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15091 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 15092 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15093 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15094 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15095 | |
| 15096 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15097 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 15098 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 15099 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15100 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15101 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 15102 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15103 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 15104 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15105 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 15106 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15107 | } |
| 15108 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15109 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15110 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15111 | spdy::SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15112 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15113 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15114 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15115 | spdy::SpdySerializedFrame resp( |
| 15116 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15117 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15118 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15119 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15120 | }; |
| 15121 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15122 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15123 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15124 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15125 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15126 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15127 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15128 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15129 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15130 | |
| 15131 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15132 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 15133 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 15134 | PRIVACY_MODE_DISABLED, |
| 15135 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 15136 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 15137 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15138 | |
| 15139 | HttpRequestInfo request; |
| 15140 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15141 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15142 | request.traffic_annotation = |
| 15143 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15144 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15145 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15146 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15147 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15148 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15149 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15150 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15151 | } |
| 15152 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15153 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15154 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 15155 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15156 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15157 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15158 | request_info.url = GURL("https://www.example.com/"); |
| 15159 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15160 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15161 | request_info.traffic_annotation = |
| 15162 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15163 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15164 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15165 | MockWrite data_writes[] = { |
| 15166 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15167 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15168 | StaticSocketDataProvider data(base::span<MockRead>(), data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15169 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15170 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15171 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15172 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15173 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15174 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15175 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15176 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15177 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15178 | rv = callback.WaitForResult(); |
| 15179 | ASSERT_EQ(error, rv); |
| 15180 | } |
| 15181 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15182 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15183 | // Just check a grab bag of cert errors. |
| 15184 | static const int kErrors[] = { |
| 15185 | ERR_CERT_COMMON_NAME_INVALID, |
| 15186 | ERR_CERT_AUTHORITY_INVALID, |
| 15187 | ERR_CERT_DATE_INVALID, |
| 15188 | }; |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 15189 | for (size_t i = 0; i < base::size(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15190 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 15191 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15192 | } |
| 15193 | } |
| 15194 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15195 | // Ensure that a client certificate is removed from the SSL client auth |
| 15196 | // cache when: |
| 15197 | // 1) No proxy is involved. |
| 15198 | // 2) TLS False Start is disabled. |
| 15199 | // 3) The initial TLS handshake requests a client certificate. |
| 15200 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15201 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15202 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15203 | request_info.url = GURL("https://www.example.com/"); |
| 15204 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15205 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15206 | request_info.traffic_annotation = |
| 15207 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15208 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15209 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15210 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15211 | |
| 15212 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 15213 | // CertificateRequest is received for the first time, the handshake will |
| 15214 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15215 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15216 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15217 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15218 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15219 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15220 | |
| 15221 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 15222 | // False Start is not being used, the result of the SSL handshake will be |
| 15223 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 15224 | // matches the result of a server sending a handshake_failure alert, |
| 15225 | // rather than a Finished message, because it requires a client |
| 15226 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15227 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15228 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15229 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15230 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15231 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15232 | |
| 15233 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 15234 | // connection to a server fails during an SSL handshake, |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15235 | // HttpNetworkTransaction will attempt to fallback to TLSv1.2 if the previous |
| 15236 | // connection was attempted with TLSv1.3. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15237 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15238 | // requiring a client certificate, this fallback handshake should also |
| 15239 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15240 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15241 | ssl_data3.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15242 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15243 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15244 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15245 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15246 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15247 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 15248 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 15249 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 15250 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15251 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15252 | // requiring a client certificate, this fallback handshake should also |
| 15253 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15254 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15255 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15256 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15257 | StaticSocketDataProvider data4; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15258 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15259 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15260 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15261 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15262 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15263 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15264 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15265 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15266 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15267 | |
| 15268 | // Complete the SSL handshake, which should abort due to requiring a |
| 15269 | // client certificate. |
| 15270 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15271 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15272 | |
| 15273 | // Indicate that no certificate should be supplied. From the perspective |
| 15274 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15275 | // certificate, so this is the same as supply a |
| 15276 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15277 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15278 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15279 | |
| 15280 | // Ensure the certificate was added to the client auth cache before |
| 15281 | // allowing the connection to continue restarting. |
| 15282 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15283 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15284 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15285 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15286 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15287 | |
| 15288 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15289 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15290 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15291 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15292 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15293 | |
| 15294 | // Ensure that the client certificate is removed from the cache on a |
| 15295 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15296 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15297 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15298 | } |
| 15299 | |
| 15300 | // Ensure that a client certificate is removed from the SSL client auth |
| 15301 | // cache when: |
| 15302 | // 1) No proxy is involved. |
| 15303 | // 2) TLS False Start is enabled. |
| 15304 | // 3) The initial TLS handshake requests a client certificate. |
| 15305 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15306 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15307 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15308 | request_info.url = GURL("https://www.example.com/"); |
| 15309 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15310 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15311 | request_info.traffic_annotation = |
| 15312 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15313 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15314 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15315 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15316 | |
| 15317 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 15318 | // return successfully after reading up to the peer's Certificate message. |
| 15319 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 15320 | // enqueue application data to be sent in the same packet as the |
| 15321 | // ChangeCipherSpec and Finished messages. |
| 15322 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 15323 | // called, which expects to process the peer's ChangeCipherSpec and |
| 15324 | // Finished messages. If there was an error negotiating with the peer, |
| 15325 | // such as due to the peer requiring a client certificate when none was |
| 15326 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 15327 | // called. |
| 15328 | |
| 15329 | // Like the non-False Start case, when a client certificate is requested by |
| 15330 | // the peer, the handshake is aborted during the Connect() call. |
| 15331 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15332 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15333 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15334 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15335 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15336 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15337 | |
| 15338 | // When a client certificate is supplied, Connect() will not be aborted |
| 15339 | // when the peer requests the certificate. Instead, the handshake will |
| 15340 | // artificially succeed, allowing the caller to write the HTTP request to |
| 15341 | // the socket. The handshake messages are not processed until Read() is |
| 15342 | // called, which then detects that the handshake was aborted, due to the |
| 15343 | // peer sending a handshake_failure because it requires a client |
| 15344 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15345 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15346 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15347 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15348 | MockRead data2_reads[] = { |
| 15349 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15350 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15351 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15352 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15353 | |
| 15354 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15355 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 15356 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15357 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15358 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15359 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15360 | StaticSocketDataProvider data3(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15361 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15362 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15363 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 15364 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15365 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15366 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15367 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15368 | StaticSocketDataProvider data4(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15369 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15370 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15371 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15372 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15373 | ssl_data5.cert_request_info = cert_request.get(); |
| 15374 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15375 | StaticSocketDataProvider data5(data2_reads, base::span<MockWrite>()); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15376 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 15377 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15378 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15379 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15380 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15381 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15382 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15383 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15384 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15385 | |
| 15386 | // Complete the SSL handshake, which should abort due to requiring a |
| 15387 | // client certificate. |
| 15388 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15389 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15390 | |
| 15391 | // Indicate that no certificate should be supplied. From the perspective |
| 15392 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15393 | // certificate, so this is the same as supply a |
| 15394 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15395 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15396 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15397 | |
| 15398 | // Ensure the certificate was added to the client auth cache before |
| 15399 | // allowing the connection to continue restarting. |
| 15400 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15401 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15402 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15403 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15404 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15405 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15406 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15407 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15408 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15409 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15410 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15411 | |
| 15412 | // Ensure that the client certificate is removed from the cache on a |
| 15413 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15414 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15415 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15416 | } |
| 15417 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15418 | // Ensure that a client certificate is removed from the SSL client auth |
| 15419 | // cache when: |
| 15420 | // 1) An HTTPS proxy is involved. |
| 15421 | // 3) The HTTPS proxy requests a client certificate. |
| 15422 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 15423 | // proxy. |
| 15424 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 15425 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15426 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15427 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 15428 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15429 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15430 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15431 | |
| 15432 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15433 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15434 | |
| 15435 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 15436 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 15437 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 15438 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15439 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15440 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15441 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15442 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15443 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15444 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15445 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15446 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15447 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15448 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15449 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15450 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15451 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 15452 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15453 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15454 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15455 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15456 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15457 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15458 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15459 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15460 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15461 | requests[0].url = GURL("https://www.example.com/"); |
| 15462 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15463 | requests[0].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15464 | requests[0].traffic_annotation = |
| 15465 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15466 | |
| 15467 | requests[1].url = GURL("http://www.example.com/"); |
| 15468 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15469 | requests[1].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15470 | requests[1].traffic_annotation = |
| 15471 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15472 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 15473 | for (size_t i = 0; i < base::size(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15474 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15475 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15476 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15477 | |
| 15478 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15479 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15480 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15481 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15482 | |
| 15483 | // Complete the SSL handshake, which should abort due to requiring a |
| 15484 | // client certificate. |
| 15485 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15486 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15487 | |
| 15488 | // Indicate that no certificate should be supplied. From the perspective |
| 15489 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15490 | // certificate, so this is the same as supply a |
| 15491 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15492 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15493 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15494 | |
| 15495 | // Ensure the certificate was added to the client auth cache before |
| 15496 | // allowing the connection to continue restarting. |
| 15497 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15498 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15499 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15500 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15501 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15502 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 15503 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15504 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15505 | HostPortPair("www.example.com", 443), &client_cert, |
| 15506 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15507 | |
| 15508 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 15509 | // then consume ssl_data3, which should also fail. The result code is |
| 15510 | // checked against what ssl_data3 should return. |
| 15511 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15512 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15513 | |
| 15514 | // Now that the new handshake has failed, ensure that the client |
| 15515 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15516 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15517 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15518 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15519 | HostPortPair("www.example.com", 443), &client_cert, |
| 15520 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15521 | } |
| 15522 | } |
| 15523 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15524 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15525 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15526 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15527 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15528 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15529 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15530 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15531 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15532 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15533 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15534 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15535 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15536 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15537 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15538 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15539 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15540 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15541 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15542 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15543 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15544 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15545 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15546 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15547 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15548 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15549 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15550 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15551 | }; |
| 15552 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15553 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15554 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15555 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15556 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15557 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15558 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15559 | HttpRequestInfo request1; |
| 15560 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15561 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15562 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15563 | request1.traffic_annotation = |
| 15564 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15565 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15566 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15567 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15568 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15569 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15570 | |
| 15571 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15572 | ASSERT_TRUE(response); |
| 15573 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15574 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15575 | |
| 15576 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15577 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15578 | EXPECT_EQ("hello!", response_data); |
| 15579 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15580 | // Preload mail.example.com into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15581 | rv = session_deps_.host_resolver->LoadIntoCache( |
| 15582 | HostPortPair("mail.example.com", 443), base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15583 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15584 | |
| 15585 | HttpRequestInfo request2; |
| 15586 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15587 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15588 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15589 | request2.traffic_annotation = |
| 15590 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15591 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15592 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15593 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15594 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15595 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15596 | |
| 15597 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15598 | ASSERT_TRUE(response); |
| 15599 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15600 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15601 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15602 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15603 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15604 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15605 | } |
| 15606 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15607 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15608 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15609 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15610 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15611 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15612 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15613 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15614 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15615 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15616 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15617 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15618 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15619 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15620 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15621 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15622 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15623 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15624 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15625 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15626 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15627 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15628 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15629 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15630 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15631 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15632 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15633 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15634 | }; |
| 15635 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15636 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15637 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15638 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15639 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15640 | |
| 15641 | TestCompletionCallback callback; |
| 15642 | HttpRequestInfo request1; |
| 15643 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15644 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15645 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15646 | request1.traffic_annotation = |
| 15647 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15648 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15649 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15650 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15651 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15652 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15653 | |
| 15654 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15655 | ASSERT_TRUE(response); |
| 15656 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15657 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15658 | |
| 15659 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15660 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15661 | EXPECT_EQ("hello!", response_data); |
| 15662 | |
| 15663 | HttpRequestInfo request2; |
| 15664 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15665 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15666 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15667 | request2.traffic_annotation = |
| 15668 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15669 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15670 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15671 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15672 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15673 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15674 | |
| 15675 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15676 | ASSERT_TRUE(response); |
| 15677 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15678 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15679 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15680 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15681 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15682 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15683 | } |
| 15684 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15685 | // Regression test for https://crbug.com/546991. |
| 15686 | // The server might not be able to serve an IP pooled request, and might send a |
| 15687 | // 421 Misdirected Request response status to indicate this. |
| 15688 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 15689 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 15690 | // Two hosts resolve to the same IP address. |
| 15691 | const std::string ip_addr = "1.2.3.4"; |
| 15692 | IPAddress ip; |
| 15693 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 15694 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15695 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15696 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15697 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 15698 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 15699 | |
| 15700 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15701 | |
| 15702 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15703 | spdy::SpdySerializedFrame req1( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15704 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 15705 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15706 | spdy::SpdySerializedFrame req2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15707 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15708 | spdy::SpdySerializedFrame rst( |
| 15709 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15710 | MockWrite writes1[] = { |
| 15711 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 15712 | CreateMockWrite(rst, 6), |
| 15713 | }; |
| 15714 | |
| 15715 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15716 | spdy::SpdySerializedFrame resp1( |
| 15717 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15718 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15719 | spdy::SpdyHeaderBlock response_headers; |
| 15720 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 15721 | spdy::SpdySerializedFrame resp2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15722 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 15723 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 15724 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 15725 | |
| 15726 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15727 | SequencedSocketData data1(connect1, reads1, writes1); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15728 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15729 | |
| 15730 | AddSSLSocketData(); |
| 15731 | |
| 15732 | // Retry the second request on a second connection. |
| 15733 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15734 | spdy::SpdySerializedFrame req3( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15735 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 15736 | MockWrite writes2[] = { |
| 15737 | CreateMockWrite(req3, 0), |
| 15738 | }; |
| 15739 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15740 | spdy::SpdySerializedFrame resp3( |
| 15741 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15742 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15743 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 15744 | MockRead(ASYNC, 0, 3)}; |
| 15745 | |
| 15746 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15747 | SequencedSocketData data2(connect2, reads2, writes2); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15748 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15749 | |
| 15750 | AddSSLSocketData(); |
| 15751 | |
| 15752 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15753 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 15754 | HostPortPair("mail.example.com", 443), base::nullopt); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15755 | EXPECT_THAT(rv, IsOk()); |
| 15756 | |
| 15757 | HttpRequestInfo request1; |
| 15758 | request1.method = "GET"; |
| 15759 | request1.url = GURL("https://www.example.org/"); |
| 15760 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15761 | request1.traffic_annotation = |
| 15762 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15763 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15764 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15765 | TestCompletionCallback callback; |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15766 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 15767 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15768 | rv = callback.WaitForResult(); |
| 15769 | EXPECT_THAT(rv, IsOk()); |
| 15770 | |
| 15771 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 15772 | ASSERT_TRUE(response); |
| 15773 | ASSERT_TRUE(response->headers); |
| 15774 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15775 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15776 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15777 | std::string response_data; |
| 15778 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 15779 | EXPECT_EQ("hello!", response_data); |
| 15780 | |
| 15781 | HttpRequestInfo request2; |
| 15782 | request2.method = "GET"; |
| 15783 | request2.url = GURL("https://mail.example.org/"); |
| 15784 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15785 | request2.traffic_annotation = |
| 15786 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15787 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15788 | |
| 15789 | BoundTestNetLog log; |
| 15790 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 15791 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15792 | rv = callback.WaitForResult(); |
| 15793 | EXPECT_THAT(rv, IsOk()); |
| 15794 | |
| 15795 | response = trans2.GetResponseInfo(); |
| 15796 | ASSERT_TRUE(response); |
| 15797 | ASSERT_TRUE(response->headers); |
| 15798 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15799 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15800 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15801 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 15802 | EXPECT_EQ("hello!", response_data); |
| 15803 | |
| 15804 | TestNetLogEntry::List entries; |
| 15805 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15806 | ExpectLogContainsSomewhere( |
| 15807 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15808 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15809 | } |
| 15810 | |
| 15811 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 15812 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 15813 | // portions of the response. |
| 15814 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 15815 | // Two hosts resolve to the same IP address. |
| 15816 | const std::string ip_addr = "1.2.3.4"; |
| 15817 | IPAddress ip; |
| 15818 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 15819 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15820 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15821 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15822 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 15823 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 15824 | |
| 15825 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15826 | |
| 15827 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15828 | spdy::SpdySerializedFrame req1( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15829 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 15830 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15831 | spdy::SpdySerializedFrame req2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15832 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15833 | spdy::SpdySerializedFrame rst( |
| 15834 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15835 | MockWrite writes1[] = { |
| 15836 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 15837 | CreateMockWrite(rst, 6), |
| 15838 | }; |
| 15839 | |
| 15840 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15841 | spdy::SpdySerializedFrame resp1( |
| 15842 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15843 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15844 | spdy::SpdyHeaderBlock response_headers; |
| 15845 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 15846 | spdy::SpdySerializedFrame resp2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15847 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 15848 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 15849 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 15850 | |
| 15851 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15852 | SequencedSocketData data1(connect1, reads1, writes1); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15853 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15854 | |
| 15855 | AddSSLSocketData(); |
| 15856 | |
| 15857 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 15858 | // Retry again. |
| 15859 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15860 | spdy::SpdySerializedFrame req3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15861 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 15862 | MockWrite writes2[] = { |
| 15863 | CreateMockWrite(req3, 0), |
| 15864 | }; |
| 15865 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15866 | spdy::SpdySerializedFrame resp3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15867 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15868 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15869 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 15870 | MockRead(ASYNC, 0, 3)}; |
| 15871 | |
| 15872 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15873 | SequencedSocketData data2(connect2, reads2, writes2); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15874 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15875 | |
| 15876 | AddSSLSocketData(); |
| 15877 | |
| 15878 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15879 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 15880 | HostPortPair("mail.example.com", 443), base::nullopt); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15881 | EXPECT_THAT(rv, IsOk()); |
| 15882 | |
| 15883 | HttpRequestInfo request1; |
| 15884 | request1.method = "GET"; |
| 15885 | request1.url = GURL("https://www.example.org/"); |
| 15886 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15887 | request1.traffic_annotation = |
| 15888 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15889 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15890 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15891 | TestCompletionCallback callback; |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15892 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 15893 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15894 | rv = callback.WaitForResult(); |
| 15895 | EXPECT_THAT(rv, IsOk()); |
| 15896 | |
| 15897 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 15898 | ASSERT_TRUE(response); |
| 15899 | ASSERT_TRUE(response->headers); |
| 15900 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15901 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15902 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15903 | std::string response_data; |
| 15904 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 15905 | EXPECT_EQ("hello!", response_data); |
| 15906 | |
| 15907 | HttpRequestInfo request2; |
| 15908 | request2.method = "GET"; |
| 15909 | request2.url = GURL("https://mail.example.org/"); |
| 15910 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15911 | request2.traffic_annotation = |
| 15912 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15913 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15914 | |
| 15915 | BoundTestNetLog log; |
| 15916 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 15917 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15918 | rv = callback.WaitForResult(); |
| 15919 | EXPECT_THAT(rv, IsOk()); |
| 15920 | |
| 15921 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 15922 | // caller. |
| 15923 | response = trans2.GetResponseInfo(); |
| 15924 | ASSERT_TRUE(response); |
| 15925 | ASSERT_TRUE(response->headers); |
| 15926 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 15927 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15928 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15929 | EXPECT_TRUE(response->ssl_info.cert); |
| 15930 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 15931 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15932 | } |
| 15933 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15934 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 15935 | UseIPConnectionPoolingWithHostCacheExpiration) { |
Eric Orth | 1da75de | 2019-02-20 21:10:34 | [diff] [blame] | 15936 | // Set up HostResolver to invalidate cached entries after 1 cached resolve. |
| 15937 | session_deps_.host_resolver = |
| 15938 | std::make_unique<MockCachingHostResolver>(1 /* cache_invalidation_num */); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15939 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15940 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15941 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15942 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15943 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15944 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15945 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15946 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15947 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15948 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15949 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15950 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15951 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15952 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15953 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15954 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15955 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15956 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15957 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15958 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15959 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15960 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15961 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15962 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15963 | }; |
| 15964 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15965 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15966 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15967 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15968 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15969 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15970 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15971 | HttpRequestInfo request1; |
| 15972 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15973 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15974 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15975 | request1.traffic_annotation = |
| 15976 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15977 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15978 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15979 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15980 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15981 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15982 | |
| 15983 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15984 | ASSERT_TRUE(response); |
| 15985 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15986 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15987 | |
| 15988 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15989 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15990 | EXPECT_EQ("hello!", response_data); |
| 15991 | |
| 15992 | // Preload cache entries into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15993 | rv = session_deps_.host_resolver->LoadIntoCache( |
| 15994 | HostPortPair("mail.example.com", 443), base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15995 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15996 | |
| 15997 | HttpRequestInfo request2; |
| 15998 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15999 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16000 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16001 | request2.traffic_annotation = |
| 16002 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16003 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16004 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16005 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16006 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16007 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16008 | |
| 16009 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16010 | ASSERT_TRUE(response); |
| 16011 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16012 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16013 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16014 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16015 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16016 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16017 | } |
| 16018 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16019 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16020 | const std::string https_url = "https://www.example.org:8080/"; |
| 16021 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16022 | |
| 16023 | // SPDY GET for HTTPS URL |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16024 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16025 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16026 | |
| 16027 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16028 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16029 | }; |
| 16030 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16031 | spdy::SpdySerializedFrame resp1( |
| 16032 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16033 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16034 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16035 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16036 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16037 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16038 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 16039 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16040 | |
| 16041 | // HTTP GET for the HTTP URL |
| 16042 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 16043 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 16044 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16045 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 16046 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16047 | }; |
| 16048 | |
| 16049 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 16050 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 16051 | MockRead(ASYNC, 2, "hello"), |
| 16052 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16053 | }; |
| 16054 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16055 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16056 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16057 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16058 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16059 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16060 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 16061 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16062 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16063 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16064 | |
| 16065 | // Start the first transaction to set up the SpdySession |
| 16066 | HttpRequestInfo request1; |
| 16067 | request1.method = "GET"; |
| 16068 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16069 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16070 | request1.traffic_annotation = |
| 16071 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16072 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16073 | TestCompletionCallback callback1; |
| 16074 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16075 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16076 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16077 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16078 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16079 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16080 | |
| 16081 | // Now, start the HTTP request |
| 16082 | HttpRequestInfo request2; |
| 16083 | request2.method = "GET"; |
| 16084 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16085 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16086 | request2.traffic_annotation = |
| 16087 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16088 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16089 | TestCompletionCallback callback2; |
| 16090 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16091 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16092 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16093 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16094 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16095 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16096 | } |
| 16097 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16098 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 16099 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16100 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16101 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 16102 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16103 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16104 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16105 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16106 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16107 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16108 | |
| 16109 | // No data should be read from the alternative, because HTTP/1.1 is |
| 16110 | // negotiated. |
| 16111 | StaticSocketDataProvider data; |
| 16112 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16113 | |
| 16114 | // 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] | 16115 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16116 | // mocked. This way the request relies on the alternate Job. |
| 16117 | StaticSocketDataProvider data_refused; |
| 16118 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 16119 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 16120 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16121 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16122 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16123 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16124 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16125 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16126 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16127 | http_server_properties->SetHttp2AlternativeService( |
| 16128 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16129 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16130 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16131 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16132 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16133 | request.url = GURL("https://www.example.org:443"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16134 | request.traffic_annotation = |
| 16135 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16136 | TestCompletionCallback callback; |
| 16137 | |
| 16138 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16139 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16140 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16141 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16142 | } |
| 16143 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16144 | // 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] | 16145 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16146 | // succeeds, the request should succeed, even if the latter fails because |
| 16147 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16148 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16149 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 16150 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16151 | |
| 16152 | // Negotiate HTTP/1.1 with alternative. |
| 16153 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16154 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16155 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 16156 | |
| 16157 | // No data should be read from the alternative, because HTTP/1.1 is |
| 16158 | // negotiated. |
| 16159 | StaticSocketDataProvider data; |
| 16160 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16161 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16162 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16163 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16164 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16165 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 16166 | |
| 16167 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16168 | MockWrite("GET / HTTP/1.1\r\n" |
| 16169 | "Host: www.example.org\r\n" |
| 16170 | "Connection: keep-alive\r\n\r\n"), |
| 16171 | MockWrite("GET /second HTTP/1.1\r\n" |
| 16172 | "Host: www.example.org\r\n" |
| 16173 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16174 | }; |
| 16175 | |
| 16176 | MockRead http_reads[] = { |
| 16177 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16178 | MockRead("Content-Type: text/html\r\n"), |
| 16179 | MockRead("Content-Length: 6\r\n\r\n"), |
| 16180 | MockRead("foobar"), |
| 16181 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16182 | MockRead("Content-Type: text/html\r\n"), |
| 16183 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16184 | MockRead("another"), |
| 16185 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16186 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16187 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16188 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16189 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16190 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16191 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16192 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16193 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16194 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16195 | http_server_properties->SetHttp2AlternativeService( |
| 16196 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16197 | |
| 16198 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 16199 | HttpRequestInfo request1; |
| 16200 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16201 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16202 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16203 | request1.traffic_annotation = |
| 16204 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16205 | TestCompletionCallback callback1; |
| 16206 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16207 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16208 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16209 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16210 | |
| 16211 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16212 | ASSERT_TRUE(response1); |
| 16213 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16214 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 16215 | |
| 16216 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16217 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16218 | EXPECT_EQ("foobar", response_data1); |
| 16219 | |
| 16220 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 16221 | // for alternative service. |
| 16222 | EXPECT_TRUE( |
| 16223 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 16224 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16225 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16226 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16227 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16228 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 16229 | HttpRequestInfo request2; |
| 16230 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16231 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16232 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16233 | request2.traffic_annotation = |
| 16234 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16235 | TestCompletionCallback callback2; |
| 16236 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16237 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16238 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16239 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16240 | |
| 16241 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16242 | ASSERT_TRUE(response2); |
| 16243 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16244 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 16245 | |
| 16246 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16247 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16248 | EXPECT_EQ("another", response_data2); |
| 16249 | } |
| 16250 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16251 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 16252 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 16253 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16254 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16255 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16256 | HostPortPair alternative("alternative.example.org", 443); |
| 16257 | std::string origin_url = "https://origin.example.org:443"; |
| 16258 | std::string alternative_url = "https://alternative.example.org:443"; |
| 16259 | |
| 16260 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 16261 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16262 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16263 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16264 | |
| 16265 | // HTTP/1.1 data for |request1| and |request2|. |
| 16266 | MockWrite http_writes[] = { |
| 16267 | MockWrite( |
| 16268 | "GET / HTTP/1.1\r\n" |
| 16269 | "Host: alternative.example.org\r\n" |
| 16270 | "Connection: keep-alive\r\n\r\n"), |
| 16271 | MockWrite( |
| 16272 | "GET / HTTP/1.1\r\n" |
| 16273 | "Host: alternative.example.org\r\n" |
| 16274 | "Connection: keep-alive\r\n\r\n"), |
| 16275 | }; |
| 16276 | |
| 16277 | MockRead http_reads[] = { |
| 16278 | MockRead( |
| 16279 | "HTTP/1.1 200 OK\r\n" |
| 16280 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16281 | "Content-Length: 40\r\n\r\n" |
| 16282 | "first HTTP/1.1 response from alternative"), |
| 16283 | MockRead( |
| 16284 | "HTTP/1.1 200 OK\r\n" |
| 16285 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16286 | "Content-Length: 41\r\n\r\n" |
| 16287 | "second HTTP/1.1 response from alternative"), |
| 16288 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16289 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16290 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16291 | |
| 16292 | // This test documents that an alternate Job should not pool to an already |
| 16293 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16294 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16295 | StaticSocketDataProvider data_refused; |
| 16296 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 16297 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 16298 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16299 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16300 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16301 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16302 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16303 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16304 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16305 | http_server_properties->SetHttp2AlternativeService( |
| 16306 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16307 | |
| 16308 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16309 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16310 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16311 | request1.method = "GET"; |
| 16312 | request1.url = GURL(alternative_url); |
| 16313 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16314 | request1.traffic_annotation = |
| 16315 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16316 | TestCompletionCallback callback1; |
| 16317 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16318 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16319 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16320 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16321 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16322 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16323 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16324 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16325 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 16326 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16327 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16328 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 16329 | |
| 16330 | // Request for origin.example.org, which has an alternative service. This |
| 16331 | // will start two Jobs: the alternative looks for connections to pool to, |
| 16332 | // 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] | 16333 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16334 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16335 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16336 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16337 | request2.method = "GET"; |
| 16338 | request2.url = GURL(origin_url); |
| 16339 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16340 | request2.traffic_annotation = |
| 16341 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16342 | TestCompletionCallback callback2; |
| 16343 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16344 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16345 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16346 | |
| 16347 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 16348 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16349 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16350 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16351 | request3.method = "GET"; |
| 16352 | request3.url = GURL(alternative_url); |
| 16353 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16354 | request3.traffic_annotation = |
| 16355 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16356 | TestCompletionCallback callback3; |
| 16357 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16358 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16359 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16360 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16361 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16362 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16363 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16364 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16365 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 16366 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16367 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16368 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 16369 | } |
| 16370 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16371 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16372 | const std::string https_url = "https://www.example.org:8080/"; |
| 16373 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16374 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16375 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16376 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16377 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16378 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16379 | const HostPortPair host_port_pair("www.example.org", 8080); |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 16380 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
| 16381 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 16382 | host_port_pair)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16383 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16384 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16385 | spdy::SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 16386 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 16387 | |
| 16388 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16389 | spdy::SpdyHeaderBlock req2_block; |
| 16390 | req2_block[spdy::kHttp2MethodHeader] = "GET"; |
| 16391 | req2_block[spdy::kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 16392 | req2_block[spdy::kHttp2SchemeHeader] = "http"; |
| 16393 | req2_block[spdy::kHttp2PathHeader] = "/"; |
| 16394 | spdy::SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16395 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16396 | |
| 16397 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16398 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 16399 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16400 | }; |
| 16401 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16402 | spdy::SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16403 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16404 | spdy::SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16405 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16406 | spdy::SpdySerializedFrame body1( |
| 16407 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 16408 | spdy::SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16409 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16410 | spdy::SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16411 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16412 | spdy::SpdySerializedFrame resp2( |
| 16413 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16414 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16415 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16416 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16417 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16418 | CreateMockRead(wrapped_resp1, 4), |
| 16419 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16420 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16421 | CreateMockRead(resp2, 8), |
| 16422 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16423 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 16424 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16425 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16426 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16427 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 16428 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16429 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 16430 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16431 | ProxyResolutionService::CreateFixedFromPacResult( |
| 16432 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 16433 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16434 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16435 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16436 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16437 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16438 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16439 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16440 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16441 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16442 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16443 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16444 | |
| 16445 | // Start the first transaction to set up the SpdySession |
| 16446 | HttpRequestInfo request1; |
| 16447 | request1.method = "GET"; |
| 16448 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16449 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16450 | request1.traffic_annotation = |
| 16451 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16452 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16453 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16454 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16455 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16456 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16457 | data1.RunUntilPaused(); |
| 16458 | base::RunLoop().RunUntilIdle(); |
| 16459 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16460 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16461 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16462 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16463 | LoadTimingInfo load_timing_info1; |
| 16464 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 16465 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 16466 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 16467 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16468 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16469 | HttpRequestInfo request2; |
| 16470 | request2.method = "GET"; |
| 16471 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16472 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16473 | request2.traffic_annotation = |
| 16474 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16475 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16476 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16477 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16478 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16479 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16480 | data1.RunUntilPaused(); |
| 16481 | base::RunLoop().RunUntilIdle(); |
| 16482 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16483 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16484 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16485 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16486 | |
| 16487 | LoadTimingInfo load_timing_info2; |
| 16488 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 16489 | // The established SPDY sessions is considered reused by the HTTP request. |
| 16490 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 16491 | // HTTP requests over a SPDY session should have a different connection |
| 16492 | // socket_log_id than requests over a tunnel. |
| 16493 | 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] | 16494 | } |
| 16495 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16496 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 16497 | // that we do not pool other origins that resolve to the same IP when |
| 16498 | // the certificate does not match the new origin. |
| 16499 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16500 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16501 | const std::string url1 = "http://www.example.org/"; |
| 16502 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16503 | const std::string ip_addr = "1.2.3.4"; |
| 16504 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16505 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16506 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16507 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16508 | // SPDY GET for HTTP URL (through SPDY proxy) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16509 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16510 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16511 | spdy::SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16512 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16513 | |
| 16514 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16515 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16516 | }; |
| 16517 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16518 | spdy::SpdySerializedFrame resp1( |
| 16519 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16520 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16521 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16522 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 16523 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16524 | }; |
| 16525 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16526 | SequencedSocketData data1(reads1, writes1); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 16527 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 16528 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16529 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 16530 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16531 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16532 | |
| 16533 | // SPDY GET for HTTPS URL (direct) |
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_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16536 | |
| 16537 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16538 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16539 | }; |
| 16540 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16541 | spdy::SpdySerializedFrame resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16542 | spdy_util_secure.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16543 | spdy::SpdySerializedFrame body2( |
| 16544 | spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16545 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16546 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16547 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16548 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16549 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16550 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16551 | |
| 16552 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 16553 | // all others direct. |
| 16554 | ProxyConfig proxy_config; |
| 16555 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16556 | session_deps_.proxy_resolution_service = |
| 16557 | std::make_unique<ProxyResolutionService>( |
| 16558 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 16559 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 16560 | nullptr, nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16561 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16562 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16563 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16564 | // Load a valid cert. Note, that this does not need to |
| 16565 | // be valid for proxy because the MockSSLClientSocket does |
| 16566 | // not actually verify it. But SpdySession will use this |
| 16567 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 16568 | ssl1.ssl_info.cert = |
| 16569 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 16570 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16571 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16572 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16573 | |
| 16574 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16575 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16576 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16577 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16578 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16579 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16580 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16581 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16582 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16583 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16584 | |
| 16585 | // Start the first transaction to set up the SpdySession |
| 16586 | HttpRequestInfo request1; |
| 16587 | request1.method = "GET"; |
| 16588 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16589 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16590 | request1.traffic_annotation = |
| 16591 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16592 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16593 | TestCompletionCallback callback1; |
| 16594 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16595 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16596 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16597 | data1.RunUntilPaused(); |
| 16598 | base::RunLoop().RunUntilIdle(); |
| 16599 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16600 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16601 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16602 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16603 | |
| 16604 | // Now, start the HTTP request |
| 16605 | HttpRequestInfo request2; |
| 16606 | request2.method = "GET"; |
| 16607 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16608 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16609 | request2.traffic_annotation = |
| 16610 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16611 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16612 | TestCompletionCallback callback2; |
| 16613 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16614 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16615 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16616 | |
| 16617 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16618 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16619 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16620 | } |
| 16621 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16622 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 16623 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 16624 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 16625 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16626 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16627 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16628 | |
| 16629 | MockRead reads1[] = { |
| 16630 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 16631 | }; |
| 16632 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16633 | SequencedSocketData data1(reads1, base::span<MockWrite>()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16634 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16635 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16636 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16637 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16638 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16639 | }; |
| 16640 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16641 | spdy::SpdySerializedFrame resp2( |
| 16642 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16643 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16644 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16645 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 16646 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16647 | }; |
| 16648 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16649 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16650 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16651 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16652 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16653 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16654 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16655 | |
| 16656 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16657 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16658 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16659 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16660 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16661 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16662 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16663 | |
| 16664 | // Start the first transaction to set up the SpdySession and verify that |
| 16665 | // connection was closed. |
| 16666 | HttpRequestInfo request1; |
| 16667 | request1.method = "GET"; |
| 16668 | request1.url = GURL(https_url); |
| 16669 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16670 | request1.traffic_annotation = |
| 16671 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16672 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16673 | TestCompletionCallback callback1; |
| 16674 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16675 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16676 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16677 | |
| 16678 | // Now, start the second request and make sure it succeeds. |
| 16679 | HttpRequestInfo request2; |
| 16680 | request2.method = "GET"; |
| 16681 | request2.url = GURL(https_url); |
| 16682 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16683 | request2.traffic_annotation = |
| 16684 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16685 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16686 | TestCompletionCallback callback2; |
| 16687 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16688 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16689 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16690 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16691 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16692 | } |
| 16693 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16694 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16695 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16696 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16697 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16698 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16699 | |
| 16700 | // Use two different hosts with different IPs so they don't get pooled. |
| 16701 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 16702 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16703 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16704 | |
| 16705 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16706 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16707 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16708 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16709 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16710 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16711 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16712 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16713 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16714 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16715 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16716 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16717 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16718 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16719 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16720 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16721 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16722 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16723 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16724 | }; |
| 16725 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16726 | // Use a separate test instance for the separate SpdySession that will be |
| 16727 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16728 | SpdyTestUtil spdy_util_2; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16729 | SequencedSocketData spdy1_data(spdy1_reads, spdy1_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 16730 | session_deps_.socket_factory->AddSocketDataProvider(&spdy1_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16731 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16732 | spdy::SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16733 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16734 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16735 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16736 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16737 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16738 | spdy_util_2.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16739 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16740 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16741 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16742 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16743 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16744 | }; |
| 16745 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16746 | SequencedSocketData spdy2_data(spdy2_reads, spdy2_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 16747 | session_deps_.socket_factory->AddSocketDataProvider(&spdy2_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16748 | |
| 16749 | MockWrite http_write[] = { |
| 16750 | MockWrite("GET / HTTP/1.1\r\n" |
| 16751 | "Host: www.a.com\r\n" |
| 16752 | "Connection: keep-alive\r\n\r\n"), |
| 16753 | }; |
| 16754 | |
| 16755 | MockRead http_read[] = { |
| 16756 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16757 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 16758 | MockRead("Content-Length: 6\r\n\r\n"), |
| 16759 | MockRead("hello!"), |
| 16760 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16761 | StaticSocketDataProvider http_data(http_read, http_write); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16762 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16763 | |
| 16764 | HostPortPair host_port_pair_a("www.a.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16765 | SpdySessionKey spdy_session_key_a( |
| 16766 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16767 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16768 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16769 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16770 | |
| 16771 | TestCompletionCallback callback; |
| 16772 | HttpRequestInfo request1; |
| 16773 | request1.method = "GET"; |
| 16774 | request1.url = GURL("https://www.a.com/"); |
| 16775 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16776 | request1.traffic_annotation = |
| 16777 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16778 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16779 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16780 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16781 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16782 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16783 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16784 | |
| 16785 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16786 | ASSERT_TRUE(response); |
| 16787 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16788 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16789 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16790 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16791 | |
| 16792 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16793 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16794 | EXPECT_EQ("hello!", response_data); |
| 16795 | trans.reset(); |
| 16796 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16797 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16798 | |
| 16799 | HostPortPair host_port_pair_b("www.b.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16800 | SpdySessionKey spdy_session_key_b( |
| 16801 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16802 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16803 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16804 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16805 | HttpRequestInfo request2; |
| 16806 | request2.method = "GET"; |
| 16807 | request2.url = GURL("https://www.b.com/"); |
| 16808 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16809 | request2.traffic_annotation = |
| 16810 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16811 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16812 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16813 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16814 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16815 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16816 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16817 | |
| 16818 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16819 | ASSERT_TRUE(response); |
| 16820 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16821 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16822 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16823 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16824 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16825 | EXPECT_EQ("hello!", response_data); |
| 16826 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16827 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16828 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16829 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16830 | |
| 16831 | HostPortPair host_port_pair_a1("www.a.com", 80); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16832 | SpdySessionKey spdy_session_key_a1( |
| 16833 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16834 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16835 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16836 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16837 | HttpRequestInfo request3; |
| 16838 | request3.method = "GET"; |
| 16839 | request3.url = GURL("http://www.a.com/"); |
| 16840 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16841 | request3.traffic_annotation = |
| 16842 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16843 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16844 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16845 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16846 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16847 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16848 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16849 | |
| 16850 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16851 | ASSERT_TRUE(response); |
| 16852 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16853 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 16854 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16855 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16856 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16857 | EXPECT_EQ("hello!", response_data); |
| 16858 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16859 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16860 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16861 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16862 | } |
| 16863 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16864 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16865 | HttpRequestInfo request; |
| 16866 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16867 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16868 | request.traffic_annotation = |
| 16869 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16870 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16871 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16872 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16873 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16874 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16875 | StaticSocketDataProvider data; |
| 16876 | data.set_connect_data(mock_connect); |
| 16877 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16878 | |
| 16879 | TestCompletionCallback callback; |
| 16880 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16881 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16882 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16883 | |
| 16884 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16885 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16886 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16887 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16888 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16889 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16890 | |
| 16891 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16892 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16893 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16894 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16895 | |
| 16896 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16897 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16898 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16899 | } |
| 16900 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16901 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16902 | HttpRequestInfo request; |
| 16903 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16904 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16905 | request.traffic_annotation = |
| 16906 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16907 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16908 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16909 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16910 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16911 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16912 | StaticSocketDataProvider data; |
| 16913 | data.set_connect_data(mock_connect); |
| 16914 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16915 | |
| 16916 | TestCompletionCallback callback; |
| 16917 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16918 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16919 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16920 | |
| 16921 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16922 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16923 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16924 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16925 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16926 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16927 | |
| 16928 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16929 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16930 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16931 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16932 | |
| 16933 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16934 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16935 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16936 | } |
| 16937 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16938 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16939 | HttpRequestInfo request; |
| 16940 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16941 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16942 | request.traffic_annotation = |
| 16943 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16944 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16945 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16946 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16947 | |
| 16948 | MockWrite data_writes[] = { |
| 16949 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16950 | }; |
| 16951 | MockRead data_reads[] = { |
| 16952 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16953 | }; |
| 16954 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16955 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16956 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16957 | |
| 16958 | TestCompletionCallback callback; |
| 16959 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16960 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16961 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16962 | |
| 16963 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16964 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16965 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16966 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16967 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16968 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16969 | } |
| 16970 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16971 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16972 | HttpRequestInfo request; |
| 16973 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16974 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16975 | request.traffic_annotation = |
| 16976 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16977 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16978 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16979 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16980 | |
| 16981 | MockWrite data_writes[] = { |
| 16982 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 16983 | }; |
| 16984 | MockRead data_reads[] = { |
| 16985 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16986 | }; |
| 16987 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16988 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16989 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16990 | |
| 16991 | TestCompletionCallback callback; |
| 16992 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16993 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16994 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16995 | |
| 16996 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16997 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16998 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16999 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17000 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17001 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 17002 | } |
| 17003 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17004 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17005 | HttpRequestInfo request; |
| 17006 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17007 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17008 | request.traffic_annotation = |
| 17009 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17010 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17011 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17012 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17013 | |
| 17014 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17015 | MockWrite( |
| 17016 | "GET / HTTP/1.1\r\n" |
| 17017 | "Host: www.example.org\r\n" |
| 17018 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17019 | }; |
| 17020 | MockRead data_reads[] = { |
| 17021 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17022 | }; |
| 17023 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17024 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17025 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17026 | |
| 17027 | TestCompletionCallback callback; |
| 17028 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17029 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17030 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17031 | |
| 17032 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17033 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17034 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17035 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17036 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17037 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 17038 | } |
| 17039 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17040 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17041 | HttpRequestInfo request; |
| 17042 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17043 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17044 | request.traffic_annotation = |
| 17045 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17046 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17047 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17048 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17049 | |
| 17050 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17051 | MockWrite( |
| 17052 | "GET / HTTP/1.1\r\n" |
| 17053 | "Host: www.example.org\r\n" |
| 17054 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17055 | }; |
| 17056 | MockRead data_reads[] = { |
| 17057 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 17058 | }; |
| 17059 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17060 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17061 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17062 | |
| 17063 | TestCompletionCallback callback; |
| 17064 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17065 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17066 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17067 | |
| 17068 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17069 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17070 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17071 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17072 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17073 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 17074 | } |
| 17075 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17076 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17077 | HttpRequestInfo request; |
| 17078 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17079 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17080 | request.extra_headers.SetHeader("X-Foo", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17081 | request.traffic_annotation = |
| 17082 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17083 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17084 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17085 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17086 | |
| 17087 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17088 | MockWrite( |
| 17089 | "GET / HTTP/1.1\r\n" |
| 17090 | "Host: www.example.org\r\n" |
| 17091 | "Connection: keep-alive\r\n" |
| 17092 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17093 | }; |
| 17094 | MockRead data_reads[] = { |
| 17095 | MockRead("HTTP/1.1 200 OK\r\n" |
| 17096 | "Content-Length: 5\r\n\r\n" |
| 17097 | "hello"), |
| 17098 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 17099 | }; |
| 17100 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17101 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17102 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17103 | |
| 17104 | TestCompletionCallback callback; |
| 17105 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17106 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17107 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17108 | |
| 17109 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17110 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17111 | |
| 17112 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17113 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17114 | std::string foo; |
| 17115 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 17116 | EXPECT_EQ("bar", foo); |
| 17117 | } |
| 17118 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17119 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 17120 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17121 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17122 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17123 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17124 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17125 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17126 | |
| 17127 | // Set up SSL request. |
| 17128 | |
| 17129 | HttpRequestInfo ssl_request; |
| 17130 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17131 | ssl_request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17132 | ssl_request.traffic_annotation = |
| 17133 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17134 | |
| 17135 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17136 | MockWrite( |
| 17137 | "GET / HTTP/1.1\r\n" |
| 17138 | "Host: www.example.org\r\n" |
| 17139 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17140 | }; |
| 17141 | MockRead ssl_reads[] = { |
| 17142 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17143 | MockRead("Content-Length: 11\r\n\r\n"), |
| 17144 | MockRead("hello world"), |
| 17145 | MockRead(SYNCHRONOUS, OK), |
| 17146 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17147 | StaticSocketDataProvider ssl_data(ssl_reads, ssl_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17148 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 17149 | |
| 17150 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17151 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17152 | |
| 17153 | // Set up HTTP request. |
| 17154 | |
| 17155 | HttpRequestInfo http_request; |
| 17156 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17157 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17158 | http_request.traffic_annotation = |
| 17159 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17160 | |
| 17161 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17162 | MockWrite( |
| 17163 | "GET / HTTP/1.1\r\n" |
| 17164 | "Host: www.example.org\r\n" |
| 17165 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17166 | }; |
| 17167 | MockRead http_reads[] = { |
| 17168 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17169 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17170 | MockRead("falafel"), |
| 17171 | MockRead(SYNCHRONOUS, OK), |
| 17172 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17173 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17174 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17175 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17176 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17177 | |
| 17178 | // Start the SSL request. |
| 17179 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17180 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17181 | ASSERT_EQ(ERR_IO_PENDING, |
| 17182 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 17183 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17184 | |
| 17185 | // Start the HTTP request. Pool should stall. |
| 17186 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17187 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17188 | ASSERT_EQ(ERR_IO_PENDING, |
| 17189 | http_trans.Start(&http_request, http_callback.callback(), |
| 17190 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17191 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17192 | |
| 17193 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17194 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17195 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17196 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17197 | EXPECT_EQ("hello world", response_data); |
| 17198 | |
| 17199 | // The SSL socket should automatically be closed, so the HTTP request can |
| 17200 | // start. |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 17201 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17202 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17203 | |
| 17204 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17205 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17206 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17207 | EXPECT_EQ("falafel", response_data); |
| 17208 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17209 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17210 | } |
| 17211 | |
| 17212 | // Tests that when a SSL connection is established but there's no corresponding |
| 17213 | // request that needs it, the new socket is closed if the transport socket pool |
| 17214 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17215 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17216 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17217 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17218 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17219 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17220 | |
| 17221 | // Set up an ssl request. |
| 17222 | |
| 17223 | HttpRequestInfo ssl_request; |
| 17224 | ssl_request.method = "GET"; |
| 17225 | ssl_request.url = GURL("https://www.foopy.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17226 | ssl_request.traffic_annotation = |
| 17227 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17228 | |
| 17229 | // No data will be sent on the SSL socket. |
| 17230 | StaticSocketDataProvider ssl_data; |
| 17231 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 17232 | |
| 17233 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17234 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17235 | |
| 17236 | // Set up HTTP request. |
| 17237 | |
| 17238 | HttpRequestInfo http_request; |
| 17239 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17240 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17241 | http_request.traffic_annotation = |
| 17242 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17243 | |
| 17244 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17245 | MockWrite( |
| 17246 | "GET / HTTP/1.1\r\n" |
| 17247 | "Host: www.example.org\r\n" |
| 17248 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17249 | }; |
| 17250 | MockRead http_reads[] = { |
| 17251 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17252 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17253 | MockRead("falafel"), |
| 17254 | MockRead(SYNCHRONOUS, OK), |
| 17255 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17256 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17257 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17258 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17259 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17260 | |
| 17261 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 17262 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 17263 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 17264 | http_stream_factory->PreconnectStreams(1, ssl_request); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 17265 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17266 | |
| 17267 | // Start the HTTP request. Pool should stall. |
| 17268 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17269 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17270 | ASSERT_EQ(ERR_IO_PENDING, |
| 17271 | http_trans.Start(&http_request, http_callback.callback(), |
| 17272 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17273 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17274 | |
| 17275 | // The SSL connection will automatically be closed once the connection is |
| 17276 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17277 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17278 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17279 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17280 | EXPECT_EQ("falafel", response_data); |
| 17281 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17282 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17283 | } |
| 17284 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17285 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17286 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17287 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17288 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17289 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17290 | |
| 17291 | HttpRequestInfo request; |
| 17292 | request.method = "POST"; |
| 17293 | request.url = GURL("http://www.foo.com/"); |
| 17294 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17295 | request.traffic_annotation = |
| 17296 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17297 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17298 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17299 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17300 | // Send headers successfully, but get an error while sending the body. |
| 17301 | MockWrite data_writes[] = { |
| 17302 | MockWrite("POST / HTTP/1.1\r\n" |
| 17303 | "Host: www.foo.com\r\n" |
| 17304 | "Connection: keep-alive\r\n" |
| 17305 | "Content-Length: 3\r\n\r\n"), |
| 17306 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17307 | }; |
| 17308 | |
| 17309 | MockRead data_reads[] = { |
| 17310 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17311 | MockRead("hello world"), |
| 17312 | MockRead(SYNCHRONOUS, OK), |
| 17313 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17314 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17315 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17316 | |
| 17317 | TestCompletionCallback callback; |
| 17318 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17319 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17320 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17321 | |
| 17322 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17323 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17324 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17325 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17326 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17327 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17328 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17329 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17330 | |
| 17331 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17332 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17333 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17334 | EXPECT_EQ("hello world", response_data); |
| 17335 | } |
| 17336 | |
| 17337 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 17338 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17339 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17340 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17341 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17342 | MockWrite data_writes[] = { |
| 17343 | MockWrite("GET / HTTP/1.1\r\n" |
| 17344 | "Host: www.foo.com\r\n" |
| 17345 | "Connection: keep-alive\r\n\r\n"), |
| 17346 | MockWrite("POST / HTTP/1.1\r\n" |
| 17347 | "Host: www.foo.com\r\n" |
| 17348 | "Connection: keep-alive\r\n" |
| 17349 | "Content-Length: 3\r\n\r\n"), |
| 17350 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17351 | }; |
| 17352 | |
| 17353 | MockRead data_reads[] = { |
| 17354 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 17355 | "Content-Length: 14\r\n\r\n"), |
| 17356 | MockRead("first response"), |
| 17357 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 17358 | "Content-Length: 15\r\n\r\n"), |
| 17359 | MockRead("second response"), |
| 17360 | MockRead(SYNCHRONOUS, OK), |
| 17361 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17362 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17363 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17364 | |
| 17365 | TestCompletionCallback callback; |
| 17366 | HttpRequestInfo request1; |
| 17367 | request1.method = "GET"; |
| 17368 | request1.url = GURL("http://www.foo.com/"); |
| 17369 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17370 | request1.traffic_annotation = |
| 17371 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17372 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17373 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17374 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17375 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17376 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17377 | |
| 17378 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17379 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17380 | |
| 17381 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17382 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17383 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17384 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17385 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 17386 | |
| 17387 | std::string response_data1; |
| 17388 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17389 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17390 | EXPECT_EQ("first response", response_data1); |
| 17391 | // Delete the transaction to release the socket back into the socket pool. |
| 17392 | trans1.reset(); |
| 17393 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17394 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17395 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17396 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17397 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17398 | |
| 17399 | HttpRequestInfo request2; |
| 17400 | request2.method = "POST"; |
| 17401 | request2.url = GURL("http://www.foo.com/"); |
| 17402 | request2.upload_data_stream = &upload_data_stream; |
| 17403 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17404 | request2.traffic_annotation = |
| 17405 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17406 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17407 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17408 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17409 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17410 | |
| 17411 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17412 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17413 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17414 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17415 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17416 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17417 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17418 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 17419 | |
| 17420 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17421 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17422 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17423 | EXPECT_EQ("second response", response_data2); |
| 17424 | } |
| 17425 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17426 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17427 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17428 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17429 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17430 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17431 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17432 | |
| 17433 | HttpRequestInfo request; |
| 17434 | request.method = "POST"; |
| 17435 | request.url = GURL("http://www.foo.com/"); |
| 17436 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17437 | request.traffic_annotation = |
| 17438 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17439 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17440 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17441 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17442 | // Send headers successfully, but get an error while sending the body. |
| 17443 | MockWrite data_writes[] = { |
| 17444 | MockWrite("POST / HTTP/1.1\r\n" |
| 17445 | "Host: www.foo.com\r\n" |
| 17446 | "Connection: keep-alive\r\n" |
| 17447 | "Content-Length: 3\r\n\r\n" |
| 17448 | "fo"), |
| 17449 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17450 | }; |
| 17451 | |
| 17452 | MockRead data_reads[] = { |
| 17453 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17454 | MockRead("hello world"), |
| 17455 | MockRead(SYNCHRONOUS, OK), |
| 17456 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17457 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17458 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17459 | |
| 17460 | TestCompletionCallback callback; |
| 17461 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17462 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17463 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17464 | |
| 17465 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17466 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17467 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17468 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17469 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17470 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17471 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17472 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17473 | |
| 17474 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17475 | rv = ReadTransaction(&trans, &response_data); |
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 | EXPECT_EQ("hello world", response_data); |
| 17478 | } |
| 17479 | |
| 17480 | // This tests the more common case than the previous test, where headers and |
| 17481 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17482 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17483 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17484 | |
| 17485 | HttpRequestInfo request; |
| 17486 | request.method = "POST"; |
| 17487 | request.url = GURL("http://www.foo.com/"); |
| 17488 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17489 | request.traffic_annotation = |
| 17490 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17491 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17492 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17493 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17494 | // Send headers successfully, but get an error while sending the body. |
| 17495 | MockWrite data_writes[] = { |
| 17496 | MockWrite("POST / HTTP/1.1\r\n" |
| 17497 | "Host: www.foo.com\r\n" |
| 17498 | "Connection: keep-alive\r\n" |
| 17499 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17500 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17501 | }; |
| 17502 | |
| 17503 | MockRead data_reads[] = { |
| 17504 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17505 | MockRead("hello world"), |
| 17506 | MockRead(SYNCHRONOUS, OK), |
| 17507 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17508 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17509 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17510 | |
| 17511 | TestCompletionCallback callback; |
| 17512 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17513 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17514 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17515 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 17516 | // they can't be merged with the body in a single send. Not currently |
| 17517 | // necessary since a chunked body is never merged with headers, but this makes |
| 17518 | // the test more future proof. |
| 17519 | base::RunLoop().RunUntilIdle(); |
| 17520 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17521 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17522 | |
| 17523 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17524 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17525 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17526 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17527 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17528 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17529 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17530 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17531 | |
| 17532 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17533 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17534 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17535 | EXPECT_EQ("hello world", response_data); |
| 17536 | } |
| 17537 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17538 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17539 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17540 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17541 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17542 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17543 | |
| 17544 | HttpRequestInfo request; |
| 17545 | request.method = "POST"; |
| 17546 | request.url = GURL("http://www.foo.com/"); |
| 17547 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17548 | request.traffic_annotation = |
| 17549 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17550 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17551 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17552 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17553 | |
| 17554 | MockWrite data_writes[] = { |
| 17555 | MockWrite("POST / HTTP/1.1\r\n" |
| 17556 | "Host: www.foo.com\r\n" |
| 17557 | "Connection: keep-alive\r\n" |
| 17558 | "Content-Length: 3\r\n\r\n"), |
| 17559 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17560 | }; |
| 17561 | |
| 17562 | MockRead data_reads[] = { |
| 17563 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17564 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17565 | MockRead("hello world"), |
| 17566 | MockRead(SYNCHRONOUS, OK), |
| 17567 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17568 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17569 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17570 | |
| 17571 | TestCompletionCallback callback; |
| 17572 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17573 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17574 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17575 | |
| 17576 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17577 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17578 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17579 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17580 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17581 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17582 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17583 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17584 | |
| 17585 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17586 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17587 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17588 | EXPECT_EQ("hello world", response_data); |
| 17589 | } |
| 17590 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17591 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17592 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17593 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17594 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17595 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17596 | |
| 17597 | HttpRequestInfo request; |
| 17598 | request.method = "POST"; |
| 17599 | request.url = GURL("http://www.foo.com/"); |
| 17600 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17601 | request.traffic_annotation = |
| 17602 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17603 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17604 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17605 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17606 | // Send headers successfully, but get an error while sending the body. |
| 17607 | MockWrite data_writes[] = { |
| 17608 | MockWrite("POST / HTTP/1.1\r\n" |
| 17609 | "Host: www.foo.com\r\n" |
| 17610 | "Connection: keep-alive\r\n" |
| 17611 | "Content-Length: 3\r\n\r\n"), |
| 17612 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17613 | }; |
| 17614 | |
| 17615 | MockRead data_reads[] = { |
| 17616 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 17617 | MockRead("hello world"), |
| 17618 | MockRead(SYNCHRONOUS, OK), |
| 17619 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17620 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17621 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17622 | |
| 17623 | TestCompletionCallback callback; |
| 17624 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17625 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17626 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17627 | |
| 17628 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17629 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17630 | } |
| 17631 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17632 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17633 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17634 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17635 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17636 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17637 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17638 | |
| 17639 | HttpRequestInfo request; |
| 17640 | request.method = "POST"; |
| 17641 | request.url = GURL("http://www.foo.com/"); |
| 17642 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17643 | request.traffic_annotation = |
| 17644 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17645 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17646 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17647 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17648 | // Send headers successfully, but get an error while sending the body. |
| 17649 | MockWrite data_writes[] = { |
| 17650 | MockWrite("POST / HTTP/1.1\r\n" |
| 17651 | "Host: www.foo.com\r\n" |
| 17652 | "Connection: keep-alive\r\n" |
| 17653 | "Content-Length: 3\r\n\r\n"), |
| 17654 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17655 | }; |
| 17656 | |
| 17657 | MockRead data_reads[] = { |
| 17658 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17659 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 17660 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 17661 | MockRead("Content-Length: 0\r\n\r\n"), |
| 17662 | MockRead(SYNCHRONOUS, OK), |
| 17663 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17664 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17665 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17666 | |
| 17667 | TestCompletionCallback callback; |
| 17668 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17669 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17670 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17671 | |
| 17672 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17673 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17674 | } |
| 17675 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17676 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17677 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17678 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17679 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17680 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17681 | |
| 17682 | HttpRequestInfo request; |
| 17683 | request.method = "POST"; |
| 17684 | request.url = GURL("http://www.foo.com/"); |
| 17685 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17686 | request.traffic_annotation = |
| 17687 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17688 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17689 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17690 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17691 | // Send headers successfully, but get an error while sending the body. |
| 17692 | MockWrite data_writes[] = { |
| 17693 | MockWrite("POST / HTTP/1.1\r\n" |
| 17694 | "Host: www.foo.com\r\n" |
| 17695 | "Connection: keep-alive\r\n" |
| 17696 | "Content-Length: 3\r\n\r\n"), |
| 17697 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17698 | }; |
| 17699 | |
| 17700 | MockRead data_reads[] = { |
| 17701 | MockRead("HTTP 0.9 rocks!"), |
| 17702 | MockRead(SYNCHRONOUS, OK), |
| 17703 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17704 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17705 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17706 | |
| 17707 | TestCompletionCallback callback; |
| 17708 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17709 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17710 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17711 | |
| 17712 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17713 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17714 | } |
| 17715 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17716 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17717 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17718 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17719 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17720 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17721 | |
| 17722 | HttpRequestInfo request; |
| 17723 | request.method = "POST"; |
| 17724 | request.url = GURL("http://www.foo.com/"); |
| 17725 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17726 | request.traffic_annotation = |
| 17727 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17728 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17729 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17730 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17731 | // Send headers successfully, but get an error while sending the body. |
| 17732 | MockWrite data_writes[] = { |
| 17733 | MockWrite("POST / HTTP/1.1\r\n" |
| 17734 | "Host: www.foo.com\r\n" |
| 17735 | "Connection: keep-alive\r\n" |
| 17736 | "Content-Length: 3\r\n\r\n"), |
| 17737 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17738 | }; |
| 17739 | |
| 17740 | MockRead data_reads[] = { |
| 17741 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 17742 | MockRead(SYNCHRONOUS, OK), |
| 17743 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17744 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17745 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17746 | |
| 17747 | TestCompletionCallback callback; |
| 17748 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17749 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17750 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17751 | |
| 17752 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17753 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17754 | } |
| 17755 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17756 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17757 | |
| 17758 | namespace { |
| 17759 | |
| 17760 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
| 17761 | headers->SetHeader("Connection", "Upgrade"); |
| 17762 | headers->SetHeader("Upgrade", "websocket"); |
| 17763 | headers->SetHeader("Origin", "http://www.example.org"); |
| 17764 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17765 | } |
| 17766 | |
| 17767 | } // namespace |
| 17768 | |
| 17769 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17770 | for (bool secure : {true, false}) { |
| 17771 | MockWrite data_writes[] = { |
| 17772 | MockWrite("GET / HTTP/1.1\r\n" |
| 17773 | "Host: www.example.org\r\n" |
| 17774 | "Connection: Upgrade\r\n" |
| 17775 | "Upgrade: websocket\r\n" |
| 17776 | "Origin: http://www.example.org\r\n" |
| 17777 | "Sec-WebSocket-Version: 13\r\n" |
| 17778 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17779 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17780 | "client_max_window_bits\r\n\r\n")}; |
| 17781 | |
| 17782 | MockRead data_reads[] = { |
| 17783 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17784 | "Upgrade: websocket\r\n" |
| 17785 | "Connection: Upgrade\r\n" |
| 17786 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
| 17787 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17788 | StaticSocketDataProvider data(data_reads, data_writes); |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17789 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17790 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17791 | if (secure) |
| 17792 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17793 | |
| 17794 | HttpRequestInfo request; |
| 17795 | request.method = "GET"; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17796 | request.url = |
| 17797 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 17798 | AddWebSocketHeaders(&request.extra_headers); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17799 | request.traffic_annotation = |
| 17800 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17801 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17802 | TestWebSocketHandshakeStreamCreateHelper |
| 17803 | websocket_handshake_stream_create_helper; |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17804 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17805 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17806 | HttpNetworkTransaction trans(LOW, session.get()); |
| 17807 | trans.SetWebSocketHandshakeStreamCreateHelper( |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17808 | &websocket_handshake_stream_create_helper); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17809 | |
| 17810 | TestCompletionCallback callback; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17811 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17812 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17813 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17814 | const HttpStreamRequest* stream_request = trans.stream_request_.get(); |
| 17815 | ASSERT_TRUE(stream_request); |
| 17816 | EXPECT_EQ(&websocket_handshake_stream_create_helper, |
| 17817 | stream_request->websocket_handshake_stream_create_helper()); |
| 17818 | |
| 17819 | rv = callback.WaitForResult(); |
| 17820 | EXPECT_THAT(rv, IsOk()); |
| 17821 | |
| 17822 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 17823 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17824 | } |
| 17825 | } |
| 17826 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17827 | // Verify that proxy headers are not sent to the destination server when |
| 17828 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17829 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17830 | HttpRequestInfo request; |
| 17831 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17832 | request.url = GURL("wss://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17833 | request.traffic_annotation = |
| 17834 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17835 | AddWebSocketHeaders(&request.extra_headers); |
| 17836 | |
| 17837 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17838 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17839 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17840 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17841 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17842 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17843 | |
| 17844 | // Since a proxy is configured, try to establish a tunnel. |
| 17845 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17846 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17847 | "Host: www.example.org:443\r\n" |
| 17848 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17849 | |
| 17850 | // After calling trans->RestartWithAuth(), this is the request we should |
| 17851 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17852 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17853 | "Host: www.example.org:443\r\n" |
| 17854 | "Proxy-Connection: keep-alive\r\n" |
| 17855 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17856 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17857 | MockWrite("GET / HTTP/1.1\r\n" |
| 17858 | "Host: www.example.org\r\n" |
| 17859 | "Connection: Upgrade\r\n" |
| 17860 | "Upgrade: websocket\r\n" |
| 17861 | "Origin: http://www.example.org\r\n" |
| 17862 | "Sec-WebSocket-Version: 13\r\n" |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17863 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17864 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17865 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17866 | |
| 17867 | // The proxy responds to the connect with a 407, using a persistent |
| 17868 | // connection. |
| 17869 | MockRead data_reads[] = { |
| 17870 | // No credentials. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17871 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 17872 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 17873 | "Content-Length: 0\r\n" |
| 17874 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17875 | |
| 17876 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17877 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17878 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17879 | "Upgrade: websocket\r\n" |
| 17880 | "Connection: Upgrade\r\n" |
| 17881 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17882 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17883 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17884 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17885 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17886 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17887 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17888 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17889 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17890 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17891 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17892 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17893 | &websocket_stream_create_helper); |
| 17894 | |
| 17895 | { |
| 17896 | TestCompletionCallback callback; |
| 17897 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17898 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17899 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17900 | |
| 17901 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17902 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17903 | } |
| 17904 | |
| 17905 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17906 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17907 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17908 | EXPECT_EQ(407, response->headers->response_code()); |
| 17909 | |
| 17910 | { |
| 17911 | TestCompletionCallback callback; |
| 17912 | |
| 17913 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 17914 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17915 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17916 | |
| 17917 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17918 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17919 | } |
| 17920 | |
| 17921 | response = trans->GetResponseInfo(); |
| 17922 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17923 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17924 | |
| 17925 | EXPECT_EQ(101, response->headers->response_code()); |
| 17926 | |
| 17927 | trans.reset(); |
| 17928 | session->CloseAllConnections(); |
| 17929 | } |
| 17930 | |
| 17931 | // Verify that proxy headers are not sent to the destination server when |
| 17932 | // establishing a tunnel for an insecure WebSocket connection. |
| 17933 | // This requires the authentication info to be injected into the auth cache |
| 17934 | // due to crbug.com/395064 |
| 17935 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17936 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17937 | HttpRequestInfo request; |
| 17938 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17939 | request.url = GURL("ws://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17940 | request.traffic_annotation = |
| 17941 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17942 | AddWebSocketHeaders(&request.extra_headers); |
| 17943 | |
| 17944 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17945 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17946 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17947 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17948 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17949 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17950 | |
| 17951 | MockWrite data_writes[] = { |
| 17952 | // Try to establish a tunnel for the WebSocket connection, with |
| 17953 | // credentials. Because WebSockets have a separate set of socket pools, |
| 17954 | // they cannot and will not use the same TCP/IP connection as the |
| 17955 | // preflight HTTP request. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17956 | MockWrite("CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 17957 | "Host: www.example.org:80\r\n" |
| 17958 | "Proxy-Connection: keep-alive\r\n" |
| 17959 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17960 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17961 | MockWrite("GET / HTTP/1.1\r\n" |
| 17962 | "Host: www.example.org\r\n" |
| 17963 | "Connection: Upgrade\r\n" |
| 17964 | "Upgrade: websocket\r\n" |
| 17965 | "Origin: http://www.example.org\r\n" |
| 17966 | "Sec-WebSocket-Version: 13\r\n" |
| 17967 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17968 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17969 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17970 | |
| 17971 | MockRead data_reads[] = { |
| 17972 | // HTTP CONNECT with credentials. |
| 17973 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17974 | |
| 17975 | // WebSocket connection established inside tunnel. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17976 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17977 | "Upgrade: websocket\r\n" |
| 17978 | "Connection: Upgrade\r\n" |
| 17979 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17980 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17981 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17982 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17983 | |
| 17984 | session->http_auth_cache()->Add( |
| 17985 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 17986 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 17987 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17988 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17989 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17990 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17991 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17992 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17993 | &websocket_stream_create_helper); |
| 17994 | |
| 17995 | TestCompletionCallback callback; |
| 17996 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17997 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17998 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17999 | |
| 18000 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18001 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18002 | |
| 18003 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18004 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18005 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18006 | |
| 18007 | EXPECT_EQ(101, response->headers->response_code()); |
| 18008 | |
| 18009 | trans.reset(); |
| 18010 | session->CloseAllConnections(); |
| 18011 | } |
| 18012 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18013 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 18014 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18015 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18016 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18017 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18018 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18019 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18020 | |
| 18021 | HttpRequestInfo request; |
| 18022 | request.method = "POST"; |
| 18023 | request.url = GURL("http://www.foo.com/"); |
| 18024 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18025 | request.traffic_annotation = |
| 18026 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18027 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18028 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18029 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18030 | MockWrite data_writes[] = { |
| 18031 | MockWrite("POST / HTTP/1.1\r\n" |
| 18032 | "Host: www.foo.com\r\n" |
| 18033 | "Connection: keep-alive\r\n" |
| 18034 | "Content-Length: 3\r\n\r\n"), |
| 18035 | MockWrite("foo"), |
| 18036 | }; |
| 18037 | |
| 18038 | MockRead data_reads[] = { |
| 18039 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18040 | MockRead(SYNCHRONOUS, OK), |
| 18041 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18042 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18043 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18044 | |
| 18045 | TestCompletionCallback callback; |
| 18046 | |
| 18047 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18048 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18049 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18050 | |
| 18051 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18052 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18053 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18054 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18055 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18056 | } |
| 18057 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18058 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18059 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18060 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18061 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18062 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18063 | |
| 18064 | HttpRequestInfo request; |
| 18065 | request.method = "POST"; |
| 18066 | request.url = GURL("http://www.foo.com/"); |
| 18067 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18068 | request.traffic_annotation = |
| 18069 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18070 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18071 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18072 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18073 | MockWrite data_writes[] = { |
| 18074 | MockWrite("POST / HTTP/1.1\r\n" |
| 18075 | "Host: www.foo.com\r\n" |
| 18076 | "Connection: keep-alive\r\n" |
| 18077 | "Content-Length: 3\r\n\r\n"), |
| 18078 | MockWrite("foo"), |
| 18079 | }; |
| 18080 | |
| 18081 | MockRead data_reads[] = { |
| 18082 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 18083 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18084 | MockRead(SYNCHRONOUS, OK), |
| 18085 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18086 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18087 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18088 | |
| 18089 | TestCompletionCallback callback; |
| 18090 | |
| 18091 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18092 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18093 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18094 | |
| 18095 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18096 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18097 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18098 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18099 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18100 | } |
| 18101 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18102 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18103 | ChunkedUploadDataStream upload_data_stream(0); |
| 18104 | |
| 18105 | HttpRequestInfo request; |
| 18106 | request.method = "POST"; |
| 18107 | request.url = GURL("http://www.foo.com/"); |
| 18108 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18109 | request.traffic_annotation = |
| 18110 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18111 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18112 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18113 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18114 | // Send headers successfully, but get an error while sending the body. |
| 18115 | MockWrite data_writes[] = { |
| 18116 | MockWrite("POST / HTTP/1.1\r\n" |
| 18117 | "Host: www.foo.com\r\n" |
| 18118 | "Connection: keep-alive\r\n" |
| 18119 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 18120 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 18121 | }; |
| 18122 | |
| 18123 | MockRead data_reads[] = { |
| 18124 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18125 | MockRead(SYNCHRONOUS, OK), |
| 18126 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18127 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18128 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18129 | |
| 18130 | TestCompletionCallback callback; |
| 18131 | |
| 18132 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18133 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18134 | |
| 18135 | base::RunLoop().RunUntilIdle(); |
| 18136 | upload_data_stream.AppendData("f", 1, false); |
| 18137 | |
| 18138 | base::RunLoop().RunUntilIdle(); |
| 18139 | upload_data_stream.AppendData("oo", 2, true); |
| 18140 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18141 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18142 | |
| 18143 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18144 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18145 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18146 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18147 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18148 | } |
| 18149 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18150 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 18151 | const std::string& accept_encoding, |
| 18152 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18153 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18154 | bool should_match) { |
| 18155 | HttpRequestInfo request; |
| 18156 | request.method = "GET"; |
| 18157 | request.url = GURL("http://www.foo.com/"); |
| 18158 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 18159 | accept_encoding); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18160 | request.traffic_annotation = |
| 18161 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18162 | |
| 18163 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 18164 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18165 | // Send headers successfully, but get an error while sending the body. |
| 18166 | MockWrite data_writes[] = { |
| 18167 | MockWrite("GET / HTTP/1.1\r\n" |
| 18168 | "Host: www.foo.com\r\n" |
| 18169 | "Connection: keep-alive\r\n" |
| 18170 | "Accept-Encoding: "), |
| 18171 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 18172 | }; |
| 18173 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18174 | std::string response_code = "200 OK"; |
| 18175 | std::string extra; |
| 18176 | if (!location.empty()) { |
| 18177 | response_code = "301 Redirect\r\nLocation: "; |
| 18178 | response_code.append(location); |
| 18179 | } |
| 18180 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18181 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18182 | MockRead("HTTP/1.0 "), |
| 18183 | MockRead(response_code.data()), |
| 18184 | MockRead("\r\nContent-Encoding: "), |
| 18185 | MockRead(content_encoding.data()), |
| 18186 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18187 | MockRead(SYNCHRONOUS, OK), |
| 18188 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18189 | StaticSocketDataProvider data(data_reads, data_writes); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18190 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 18191 | |
| 18192 | TestCompletionCallback callback; |
| 18193 | |
| 18194 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18195 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18196 | |
| 18197 | rv = callback.WaitForResult(); |
| 18198 | if (should_match) { |
| 18199 | EXPECT_THAT(rv, IsOk()); |
| 18200 | } else { |
| 18201 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 18202 | } |
| 18203 | } |
| 18204 | |
| 18205 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18206 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18207 | } |
| 18208 | |
| 18209 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18210 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 18211 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18212 | } |
| 18213 | |
| 18214 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 18215 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18216 | "", false); |
| 18217 | } |
| 18218 | |
| 18219 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 18220 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 18221 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18222 | } |
| 18223 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18224 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 18225 | ProxyConfig proxy_config; |
| 18226 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18227 | proxy_config.set_pac_mandatory(true); |
| 18228 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18229 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18230 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18231 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Bence Béky | 8f9d7d395 | 2017-10-09 19:58:04 | [diff] [blame] | 18232 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18233 | |
| 18234 | HttpRequestInfo request; |
| 18235 | request.method = "GET"; |
| 18236 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18237 | request.traffic_annotation = |
| 18238 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18239 | |
| 18240 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18241 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18242 | |
| 18243 | TestCompletionCallback callback; |
| 18244 | |
| 18245 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18246 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18247 | EXPECT_THAT(callback.WaitForResult(), |
| 18248 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18249 | } |
| 18250 | |
| 18251 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 18252 | ProxyConfig proxy_config; |
| 18253 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18254 | proxy_config.set_pac_mandatory(true); |
| 18255 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 18256 | new MockAsyncProxyResolverFactory(false); |
| 18257 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18258 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18259 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18260 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18261 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18262 | HttpRequestInfo request; |
| 18263 | request.method = "GET"; |
| 18264 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18265 | request.traffic_annotation = |
| 18266 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18267 | |
| 18268 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18269 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18270 | |
| 18271 | TestCompletionCallback callback; |
| 18272 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18273 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18274 | |
| 18275 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 18276 | ERR_FAILED, &resolver); |
| 18277 | EXPECT_THAT(callback.WaitForResult(), |
| 18278 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18279 | } |
| 18280 | |
| 18281 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18282 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18283 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18284 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18285 | session_deps_.enable_quic = false; |
| 18286 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18287 | |
| 18288 | HttpRequestInfo request; |
| 18289 | request.method = "GET"; |
| 18290 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18291 | request.traffic_annotation = |
| 18292 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18293 | |
| 18294 | TestCompletionCallback callback; |
| 18295 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18296 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18297 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18298 | |
| 18299 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 18300 | } |
| 18301 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18302 | //----------------------------------------------------------------------------- |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18303 | // Reporting tests |
| 18304 | |
| 18305 | #if BUILDFLAG(ENABLE_REPORTING) |
| 18306 | class HttpNetworkTransactionReportingTest : public HttpNetworkTransactionTest { |
| 18307 | protected: |
| 18308 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18309 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18310 | auto test_reporting_context = std::make_unique<TestReportingContext>( |
| 18311 | &clock_, &tick_clock_, ReportingPolicy()); |
| 18312 | test_reporting_context_ = test_reporting_context.get(); |
| 18313 | session_deps_.reporting_service = |
| 18314 | ReportingService::CreateForTesting(std::move(test_reporting_context)); |
| 18315 | } |
| 18316 | |
| 18317 | TestReportingContext* reporting_context() const { |
| 18318 | return test_reporting_context_; |
| 18319 | } |
| 18320 | |
| 18321 | void clear_reporting_service() { |
| 18322 | session_deps_.reporting_service.reset(); |
| 18323 | test_reporting_context_ = nullptr; |
| 18324 | } |
| 18325 | |
| 18326 | // Makes an HTTPS request that should install a valid Reporting policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18327 | void RequestPolicy(CertStatus cert_status = 0) { |
| 18328 | HttpRequestInfo request; |
| 18329 | request.method = "GET"; |
| 18330 | request.url = GURL(url_); |
| 18331 | request.traffic_annotation = |
| 18332 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18333 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18334 | MockWrite data_writes[] = { |
| 18335 | MockWrite("GET / HTTP/1.1\r\n" |
| 18336 | "Host: www.example.org\r\n" |
| 18337 | "Connection: keep-alive\r\n\r\n"), |
| 18338 | }; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18339 | MockRead data_reads[] = { |
| 18340 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18341 | MockRead("Report-To: {\"group\": \"nel\", \"max_age\": 86400, " |
| 18342 | "\"endpoints\": [{\"url\": " |
| 18343 | "\"https://www.example.org/upload/\"}]}\r\n"), |
| 18344 | MockRead("\r\n"), |
| 18345 | MockRead("hello world"), |
| 18346 | MockRead(SYNCHRONOUS, OK), |
| 18347 | }; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18348 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18349 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18350 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18351 | |
| 18352 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18353 | if (request.url.SchemeIsCryptographic()) { |
| 18354 | ssl.ssl_info.cert = |
| 18355 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18356 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18357 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18358 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18359 | } |
| 18360 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18361 | TestCompletionCallback callback; |
| 18362 | auto session = CreateSession(&session_deps_); |
| 18363 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18364 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18365 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18366 | } |
| 18367 | |
| 18368 | protected: |
| 18369 | std::string url_ = "https://www.example.org/"; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18370 | |
| 18371 | private: |
| 18372 | TestReportingContext* test_reporting_context_; |
| 18373 | }; |
| 18374 | |
| 18375 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18376 | DontProcessReportToHeaderNoService) { |
| 18377 | base::HistogramTester histograms; |
| 18378 | clear_reporting_service(); |
| 18379 | RequestPolicy(); |
| 18380 | histograms.ExpectBucketCount( |
| 18381 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18382 | ReportingHeaderParser::HeaderOutcome::DISCARDED_NO_REPORTING_SERVICE, 1); |
| 18383 | } |
| 18384 | |
| 18385 | TEST_F(HttpNetworkTransactionReportingTest, DontProcessReportToHeaderHttp) { |
| 18386 | base::HistogramTester histograms; |
| 18387 | url_ = "http://www.example.org/"; |
| 18388 | RequestPolicy(); |
| 18389 | histograms.ExpectBucketCount( |
| 18390 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18391 | ReportingHeaderParser::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18392 | } |
| 18393 | |
| 18394 | TEST_F(HttpNetworkTransactionReportingTest, ProcessReportToHeaderHttps) { |
| 18395 | RequestPolicy(); |
| 18396 | std::vector<const ReportingClient*> clients; |
| 18397 | reporting_context()->cache()->GetClients(&clients); |
| 18398 | ASSERT_EQ(1u, clients.size()); |
| 18399 | const auto* client = clients[0]; |
| 18400 | EXPECT_EQ(url::Origin::Create(GURL("https://www.example.org/")), |
| 18401 | client->origin); |
| 18402 | EXPECT_EQ(GURL("https://www.example.org/upload/"), client->endpoint); |
| 18403 | EXPECT_EQ("nel", client->group); |
| 18404 | } |
| 18405 | |
| 18406 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18407 | DontProcessReportToHeaderInvalidHttps) { |
| 18408 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18409 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18410 | RequestPolicy(cert_status); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18411 | histograms.ExpectBucketCount( |
| 18412 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18413 | ReportingHeaderParser::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, 1); |
| 18414 | } |
| 18415 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 18416 | |
| 18417 | //----------------------------------------------------------------------------- |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18418 | // Network Error Logging tests |
| 18419 | |
| 18420 | #if BUILDFLAG(ENABLE_REPORTING) |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18421 | namespace { |
| 18422 | |
| 18423 | const char kUserAgent[] = "Mozilla/1.0"; |
| 18424 | const char kReferrer[] = "https://www.referrer.org/"; |
| 18425 | |
| 18426 | } // namespace |
| 18427 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18428 | class HttpNetworkTransactionNetworkErrorLoggingTest |
| 18429 | : public HttpNetworkTransactionTest { |
| 18430 | protected: |
| 18431 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18432 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18433 | auto network_error_logging_service = |
| 18434 | std::make_unique<TestNetworkErrorLoggingService>(); |
| 18435 | test_network_error_logging_service_ = network_error_logging_service.get(); |
| 18436 | session_deps_.network_error_logging_service = |
| 18437 | std::move(network_error_logging_service); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18438 | |
| 18439 | extra_headers_.SetHeader("User-Agent", kUserAgent); |
| 18440 | extra_headers_.SetHeader("Referer", kReferrer); |
| 18441 | |
| 18442 | request_.method = "GET"; |
| 18443 | request_.url = GURL(url_); |
| 18444 | request_.extra_headers = extra_headers_; |
| 18445 | request_.reporting_upload_depth = reporting_upload_depth_; |
| 18446 | request_.traffic_annotation = |
| 18447 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18448 | } |
| 18449 | |
| 18450 | TestNetworkErrorLoggingService* network_error_logging_service() const { |
| 18451 | return test_network_error_logging_service_; |
| 18452 | } |
| 18453 | |
| 18454 | void clear_network_error_logging_service() { |
| 18455 | session_deps_.network_error_logging_service.reset(); |
| 18456 | test_network_error_logging_service_ = nullptr; |
| 18457 | } |
| 18458 | |
| 18459 | // Makes an HTTPS request that should install a valid NEL policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18460 | void RequestPolicy(CertStatus cert_status = 0) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18461 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18462 | MockWrite data_writes[] = { |
| 18463 | MockWrite("GET / HTTP/1.1\r\n" |
| 18464 | "Host: www.example.org\r\n" |
| 18465 | "Connection: keep-alive\r\n"), |
| 18466 | MockWrite(ASYNC, extra_header_string.data(), |
| 18467 | extra_header_string.size()), |
| 18468 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18469 | MockRead data_reads[] = { |
| 18470 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18471 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 18472 | MockRead("\r\n"), |
| 18473 | MockRead("hello world"), |
| 18474 | MockRead(SYNCHRONOUS, OK), |
| 18475 | }; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18476 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18477 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18478 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18479 | |
| 18480 | SSLSocketDataProvider ssl(ASYNC, OK); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18481 | if (request_.url.SchemeIsCryptographic()) { |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18482 | ssl.ssl_info.cert = |
| 18483 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18484 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18485 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18486 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18487 | } |
| 18488 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18489 | TestCompletionCallback callback; |
| 18490 | auto session = CreateSession(&session_deps_); |
| 18491 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18492 | int rv = trans.Start(&request_, callback.callback(), NetLogWithSource()); |
| 18493 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18494 | |
| 18495 | std::string response_data; |
| 18496 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 18497 | EXPECT_EQ("hello world", response_data); |
| 18498 | } |
| 18499 | |
| 18500 | void CheckReport(size_t index, |
| 18501 | int status_code, |
| 18502 | int error_type, |
| 18503 | IPAddress server_ip = IPAddress::IPv4Localhost()) { |
| 18504 | ASSERT_LT(index, network_error_logging_service()->errors().size()); |
| 18505 | |
| 18506 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18507 | network_error_logging_service()->errors()[index]; |
| 18508 | EXPECT_EQ(url_, error.uri); |
| 18509 | EXPECT_EQ(kReferrer, error.referrer); |
| 18510 | EXPECT_EQ(kUserAgent, error.user_agent); |
| 18511 | EXPECT_EQ(server_ip, error.server_ip); |
| 18512 | EXPECT_EQ("http/1.1", error.protocol); |
| 18513 | EXPECT_EQ("GET", error.method); |
| 18514 | EXPECT_EQ(status_code, error.status_code); |
| 18515 | EXPECT_EQ(error_type, error.type); |
| 18516 | EXPECT_EQ(0, error.reporting_upload_depth); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18517 | } |
| 18518 | |
| 18519 | protected: |
| 18520 | std::string url_ = "https://www.example.org/"; |
| 18521 | CertStatus cert_status_ = 0; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18522 | HttpRequestInfo request_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18523 | HttpRequestHeaders extra_headers_; |
| 18524 | int reporting_upload_depth_ = 0; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18525 | |
| 18526 | private: |
| 18527 | TestNetworkErrorLoggingService* test_network_error_logging_service_; |
| 18528 | }; |
| 18529 | |
| 18530 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18531 | DontProcessNelHeaderNoService) { |
| 18532 | base::HistogramTester histograms; |
| 18533 | clear_network_error_logging_service(); |
| 18534 | RequestPolicy(); |
| 18535 | histograms.ExpectBucketCount( |
| 18536 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18537 | NetworkErrorLoggingService::HeaderOutcome:: |
| 18538 | DISCARDED_NO_NETWORK_ERROR_LOGGING_SERVICE, |
| 18539 | 1); |
| 18540 | } |
| 18541 | |
| 18542 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18543 | DontProcessNelHeaderHttp) { |
| 18544 | base::HistogramTester histograms; |
| 18545 | url_ = "http://www.example.org/"; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18546 | request_.url = GURL(url_); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18547 | RequestPolicy(); |
| 18548 | histograms.ExpectBucketCount( |
| 18549 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18550 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18551 | } |
| 18552 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 18553 | // Don't set NEL policies received on a proxied connection. |
| 18554 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18555 | DontProcessNelHeaderProxy) { |
| 18556 | session_deps_.proxy_resolution_service = |
| 18557 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18558 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18559 | BoundTestNetLog log; |
| 18560 | session_deps_.net_log = log.bound().net_log(); |
| 18561 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18562 | |
| 18563 | HttpRequestInfo request; |
| 18564 | request.method = "GET"; |
| 18565 | request.url = GURL("https://www.example.org/"); |
| 18566 | request.traffic_annotation = |
| 18567 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18568 | |
| 18569 | // Since we have proxy, should try to establish tunnel. |
| 18570 | MockWrite data_writes1[] = { |
| 18571 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 18572 | "Host: www.example.org:443\r\n" |
| 18573 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 18574 | |
| 18575 | MockWrite("GET / HTTP/1.1\r\n" |
| 18576 | "Host: www.example.org\r\n" |
| 18577 | "Connection: keep-alive\r\n\r\n"), |
| 18578 | }; |
| 18579 | |
| 18580 | MockRead data_reads1[] = { |
| 18581 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 18582 | |
| 18583 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 18584 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 18585 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18586 | MockRead("Content-Length: 100\r\n\r\n"), |
| 18587 | MockRead(SYNCHRONOUS, OK), |
| 18588 | }; |
| 18589 | |
| 18590 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18591 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18592 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18593 | ssl.ssl_info.cert = |
| 18594 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18595 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 18596 | ssl.ssl_info.cert_status = 0; |
| 18597 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18598 | |
| 18599 | TestCompletionCallback callback1; |
| 18600 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18601 | |
| 18602 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
| 18603 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18604 | |
| 18605 | rv = callback1.WaitForResult(); |
| 18606 | EXPECT_THAT(rv, IsOk()); |
| 18607 | |
| 18608 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 18609 | ASSERT_TRUE(response); |
| 18610 | EXPECT_EQ(200, response->headers->response_code()); |
| 18611 | EXPECT_TRUE(response->was_fetched_via_proxy); |
| 18612 | |
| 18613 | // No NEL header was set. |
| 18614 | EXPECT_EQ(0u, network_error_logging_service()->headers().size()); |
| 18615 | } |
| 18616 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18617 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ProcessNelHeaderHttps) { |
| 18618 | RequestPolicy(); |
| 18619 | ASSERT_EQ(1u, network_error_logging_service()->headers().size()); |
| 18620 | const auto& header = network_error_logging_service()->headers()[0]; |
| 18621 | EXPECT_EQ(url::Origin::Create(GURL("https://www.example.org/")), |
| 18622 | header.origin); |
| 18623 | EXPECT_EQ(IPAddress::IPv4Localhost(), header.received_ip_address); |
| 18624 | EXPECT_EQ("{\"report_to\": \"nel\", \"max_age\": 86400}", header.value); |
| 18625 | } |
| 18626 | |
| 18627 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18628 | DontProcessNelHeaderInvalidHttps) { |
| 18629 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18630 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18631 | RequestPolicy(cert_status); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18632 | histograms.ExpectBucketCount( |
| 18633 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18634 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, |
| 18635 | 1); |
| 18636 | } |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18637 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18638 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, CreateReportSuccess) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18639 | RequestPolicy(); |
| 18640 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18641 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 18642 | } |
| 18643 | |
| 18644 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18645 | CreateReportErrorAfterStart) { |
| 18646 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18647 | auto trans = |
| 18648 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18649 | |
| 18650 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
| 18651 | StaticSocketDataProvider data; |
| 18652 | data.set_connect_data(mock_connect); |
| 18653 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18654 | |
| 18655 | TestCompletionCallback callback; |
| 18656 | |
| 18657 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18658 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 18659 | |
| 18660 | trans.reset(); |
| 18661 | |
| 18662 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18663 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 18664 | IPAddress() /* server_ip */); |
| 18665 | } |
| 18666 | |
| 18667 | // Same as above except the error is ASYNC |
| 18668 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18669 | CreateReportErrorAfterStartAsync) { |
| 18670 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18671 | auto trans = |
| 18672 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18673 | |
| 18674 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
| 18675 | StaticSocketDataProvider data; |
| 18676 | data.set_connect_data(mock_connect); |
| 18677 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18678 | |
| 18679 | TestCompletionCallback callback; |
| 18680 | |
| 18681 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18682 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 18683 | |
| 18684 | trans.reset(); |
| 18685 | |
| 18686 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18687 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 18688 | IPAddress() /* server_ip */); |
| 18689 | } |
| 18690 | |
| 18691 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18692 | CreateReportReadBodyError) { |
| 18693 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18694 | MockWrite data_writes[] = { |
| 18695 | MockWrite("GET / HTTP/1.1\r\n" |
| 18696 | "Host: www.example.org\r\n" |
| 18697 | "Connection: keep-alive\r\n"), |
| 18698 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18699 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18700 | MockRead data_reads[] = { |
| 18701 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18702 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 18703 | MockRead("hello world"), |
| 18704 | MockRead(SYNCHRONOUS, OK), |
| 18705 | }; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18706 | |
| 18707 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18708 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 18709 | |
| 18710 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18711 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18712 | |
| 18713 | // Log start time |
| 18714 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18715 | |
| 18716 | TestCompletionCallback callback; |
| 18717 | auto session = CreateSession(&session_deps_); |
| 18718 | auto trans = |
| 18719 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18720 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18721 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18722 | |
| 18723 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18724 | ASSERT_TRUE(response); |
| 18725 | |
| 18726 | EXPECT_TRUE(response->headers); |
| 18727 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 18728 | |
| 18729 | std::string response_data; |
| 18730 | rv = ReadTransaction(trans.get(), &response_data); |
| 18731 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 18732 | |
| 18733 | trans.reset(); |
| 18734 | |
| 18735 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18736 | |
| 18737 | CheckReport(0 /* index */, 200 /* status_code */, |
| 18738 | ERR_CONTENT_LENGTH_MISMATCH); |
| 18739 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18740 | network_error_logging_service()->errors()[0]; |
| 18741 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 18742 | } |
| 18743 | |
| 18744 | // Same as above except the final read is ASYNC. |
| 18745 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18746 | CreateReportReadBodyErrorAsync) { |
| 18747 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18748 | MockWrite data_writes[] = { |
| 18749 | MockWrite("GET / HTTP/1.1\r\n" |
| 18750 | "Host: www.example.org\r\n" |
| 18751 | "Connection: keep-alive\r\n"), |
| 18752 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18753 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18754 | MockRead data_reads[] = { |
| 18755 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18756 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 18757 | MockRead("hello world"), |
| 18758 | MockRead(ASYNC, OK), |
| 18759 | }; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18760 | |
| 18761 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18762 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 18763 | |
| 18764 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18765 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18766 | |
| 18767 | // Log start time |
| 18768 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18769 | |
| 18770 | TestCompletionCallback callback; |
| 18771 | auto session = CreateSession(&session_deps_); |
| 18772 | auto trans = |
| 18773 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18774 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18775 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18776 | |
| 18777 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18778 | ASSERT_TRUE(response); |
| 18779 | |
| 18780 | EXPECT_TRUE(response->headers); |
| 18781 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 18782 | |
| 18783 | std::string response_data; |
| 18784 | rv = ReadTransaction(trans.get(), &response_data); |
| 18785 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 18786 | |
| 18787 | trans.reset(); |
| 18788 | |
| 18789 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18790 | |
| 18791 | CheckReport(0 /* index */, 200 /* status_code */, |
| 18792 | ERR_CONTENT_LENGTH_MISMATCH); |
| 18793 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18794 | network_error_logging_service()->errors()[0]; |
| 18795 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 18796 | } |
| 18797 | |
| 18798 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18799 | CreateReportRestartWithAuth) { |
| 18800 | std::string extra_header_string = extra_headers_.ToString(); |
| 18801 | static const base::TimeDelta kSleepDuration = |
| 18802 | base::TimeDelta::FromMilliseconds(10); |
| 18803 | |
| 18804 | MockWrite data_writes1[] = { |
| 18805 | MockWrite("GET / HTTP/1.1\r\n" |
| 18806 | "Host: www.example.org\r\n" |
| 18807 | "Connection: keep-alive\r\n"), |
| 18808 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18809 | }; |
| 18810 | |
| 18811 | MockRead data_reads1[] = { |
| 18812 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 18813 | // Give a couple authenticate options (only the middle one is actually |
| 18814 | // supported). |
| 18815 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 18816 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 18817 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 18818 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18819 | // Large content-length -- won't matter, as connection will be reset. |
| 18820 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 18821 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 18822 | }; |
| 18823 | |
| 18824 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18825 | // be issuing -- the final header line contains the credentials. |
| 18826 | MockWrite data_writes2[] = { |
| 18827 | MockWrite("GET / HTTP/1.1\r\n" |
| 18828 | "Host: www.example.org\r\n" |
| 18829 | "Connection: keep-alive\r\n" |
| 18830 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 18831 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18832 | }; |
| 18833 | |
| 18834 | // Lastly, the server responds with the actual content. |
| 18835 | MockRead data_reads2[] = { |
| 18836 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 18837 | MockRead("hello world"), |
| 18838 | MockRead(SYNCHRONOUS, OK), |
| 18839 | }; |
| 18840 | |
| 18841 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18842 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 18843 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18844 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18845 | |
| 18846 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18847 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18848 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18849 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18850 | |
| 18851 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18852 | base::TimeTicks restart_time; |
| 18853 | |
| 18854 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18855 | auto trans = |
| 18856 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18857 | |
| 18858 | TestCompletionCallback callback1; |
| 18859 | |
| 18860 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18861 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18862 | |
| 18863 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18864 | |
| 18865 | TestCompletionCallback callback2; |
| 18866 | |
| 18867 | // Wait 10 ms then restart with auth |
| 18868 | FastForwardBy(kSleepDuration); |
| 18869 | restart_time = base::TimeTicks::Now(); |
| 18870 | rv = |
| 18871 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 18872 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18873 | |
| 18874 | std::string response_data; |
| 18875 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 18876 | EXPECT_EQ("hello world", response_data); |
| 18877 | |
| 18878 | trans.reset(); |
| 18879 | |
| 18880 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 18881 | // retry. Note that we don't report the error draining the body, as the first |
| 18882 | // request already generated a report for the auth challenge. |
| 18883 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 18884 | |
| 18885 | // Check error report contents |
| 18886 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 18887 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 18888 | |
| 18889 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 18890 | network_error_logging_service()->errors()[0]; |
| 18891 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 18892 | network_error_logging_service()->errors()[1]; |
| 18893 | |
| 18894 | // Sanity-check elapsed time values |
| 18895 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 18896 | // Check that the start time is refreshed when restarting with auth. |
| 18897 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 18898 | } |
| 18899 | |
| 18900 | // Same as above, except draining the body before restarting fails |
| 18901 | // asynchronously. |
| 18902 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18903 | CreateReportRestartWithAuthAsync) { |
| 18904 | std::string extra_header_string = extra_headers_.ToString(); |
| 18905 | static const base::TimeDelta kSleepDuration = |
| 18906 | base::TimeDelta::FromMilliseconds(10); |
| 18907 | |
| 18908 | MockWrite data_writes1[] = { |
| 18909 | MockWrite("GET / HTTP/1.1\r\n" |
| 18910 | "Host: www.example.org\r\n" |
| 18911 | "Connection: keep-alive\r\n"), |
| 18912 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18913 | }; |
| 18914 | |
| 18915 | MockRead data_reads1[] = { |
| 18916 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 18917 | // Give a couple authenticate options (only the middle one is actually |
| 18918 | // supported). |
| 18919 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 18920 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 18921 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 18922 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18923 | // Large content-length -- won't matter, as connection will be reset. |
| 18924 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 18925 | MockRead(ASYNC, ERR_FAILED), |
| 18926 | }; |
| 18927 | |
| 18928 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18929 | // be issuing -- the final header line contains the credentials. |
| 18930 | MockWrite data_writes2[] = { |
| 18931 | MockWrite("GET / HTTP/1.1\r\n" |
| 18932 | "Host: www.example.org\r\n" |
| 18933 | "Connection: keep-alive\r\n" |
| 18934 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 18935 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18936 | }; |
| 18937 | |
| 18938 | // Lastly, the server responds with the actual content. |
| 18939 | MockRead data_reads2[] = { |
| 18940 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 18941 | MockRead("hello world"), |
| 18942 | MockRead(SYNCHRONOUS, OK), |
| 18943 | }; |
| 18944 | |
| 18945 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18946 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 18947 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18948 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18949 | |
| 18950 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18951 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18952 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18953 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18954 | |
| 18955 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18956 | base::TimeTicks restart_time; |
| 18957 | |
| 18958 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18959 | auto trans = |
| 18960 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18961 | |
| 18962 | TestCompletionCallback callback1; |
| 18963 | |
| 18964 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18965 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18966 | |
| 18967 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18968 | |
| 18969 | TestCompletionCallback callback2; |
| 18970 | |
| 18971 | // Wait 10 ms then restart with auth |
| 18972 | FastForwardBy(kSleepDuration); |
| 18973 | restart_time = base::TimeTicks::Now(); |
| 18974 | rv = |
| 18975 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 18976 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18977 | |
| 18978 | std::string response_data; |
| 18979 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 18980 | EXPECT_EQ("hello world", response_data); |
| 18981 | |
| 18982 | trans.reset(); |
| 18983 | |
| 18984 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 18985 | // retry. Note that we don't report the error draining the body, as the first |
| 18986 | // request already generated a report for the auth challenge. |
| 18987 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 18988 | |
| 18989 | // Check error report contents |
| 18990 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 18991 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 18992 | |
| 18993 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 18994 | network_error_logging_service()->errors()[0]; |
| 18995 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 18996 | network_error_logging_service()->errors()[1]; |
| 18997 | |
| 18998 | // Sanity-check elapsed time values |
| 18999 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 19000 | // Check that the start time is refreshed when restarting with auth. |
| 19001 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 19002 | } |
| 19003 | |
| 19004 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19005 | CreateReportRetryKeepAliveConnectionReset) { |
| 19006 | std::string extra_header_string = extra_headers_.ToString(); |
| 19007 | MockWrite data_writes1[] = { |
| 19008 | MockWrite("GET / HTTP/1.1\r\n" |
| 19009 | "Host: www.example.org\r\n" |
| 19010 | "Connection: keep-alive\r\n"), |
| 19011 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19012 | MockWrite("GET / HTTP/1.1\r\n" |
| 19013 | "Host: www.example.org\r\n" |
| 19014 | "Connection: keep-alive\r\n"), |
| 19015 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19016 | }; |
| 19017 | |
| 19018 | MockRead data_reads1[] = { |
| 19019 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19020 | MockRead("hello"), |
| 19021 | // Connection is reset |
| 19022 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 19023 | }; |
| 19024 | |
| 19025 | // Successful retry |
| 19026 | MockRead data_reads2[] = { |
| 19027 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19028 | MockRead("world"), |
| 19029 | MockRead(ASYNC, OK), |
| 19030 | }; |
| 19031 | |
| 19032 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19033 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 19034 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19035 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19036 | |
| 19037 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 19038 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 19039 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 19040 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 19041 | |
| 19042 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19043 | auto trans1 = |
| 19044 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19045 | |
| 19046 | TestCompletionCallback callback1; |
| 19047 | |
| 19048 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 19049 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19050 | |
| 19051 | std::string response_data; |
| 19052 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19053 | EXPECT_EQ("hello", response_data); |
| 19054 | |
| 19055 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19056 | |
| 19057 | auto trans2 = |
| 19058 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19059 | |
| 19060 | TestCompletionCallback callback2; |
| 19061 | |
| 19062 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 19063 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19064 | |
| 19065 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19066 | EXPECT_EQ("world", response_data); |
| 19067 | |
| 19068 | trans1.reset(); |
| 19069 | trans2.reset(); |
| 19070 | |
| 19071 | // One OK report from first request, then a ERR_CONNECTION_RESET report from |
| 19072 | // the second request, then an OK report from the successful retry. |
| 19073 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19074 | |
| 19075 | // Check error report contents |
| 19076 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19077 | CheckReport(1 /* index */, 0 /* status_code */, ERR_CONNECTION_RESET); |
| 19078 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 19079 | } |
| 19080 | |
| 19081 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19082 | CreateReportRetryKeepAlive408) { |
| 19083 | std::string extra_header_string = extra_headers_.ToString(); |
| 19084 | MockWrite data_writes1[] = { |
| 19085 | MockWrite("GET / HTTP/1.1\r\n" |
| 19086 | "Host: www.example.org\r\n" |
| 19087 | "Connection: keep-alive\r\n"), |
| 19088 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19089 | MockWrite("GET / HTTP/1.1\r\n" |
| 19090 | "Host: www.example.org\r\n" |
| 19091 | "Connection: keep-alive\r\n"), |
| 19092 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19093 | }; |
| 19094 | |
| 19095 | MockRead data_reads1[] = { |
| 19096 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19097 | MockRead("hello"), |
| 19098 | // 408 Request Timeout |
| 19099 | MockRead(SYNCHRONOUS, |
| 19100 | "HTTP/1.1 408 Request Timeout\r\n" |
| 19101 | "Connection: Keep-Alive\r\n" |
| 19102 | "Content-Length: 6\r\n\r\n" |
| 19103 | "Pickle"), |
| 19104 | }; |
| 19105 | |
| 19106 | // Successful retry |
| 19107 | MockRead data_reads2[] = { |
| 19108 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19109 | MockRead("world"), |
| 19110 | MockRead(ASYNC, OK), |
| 19111 | }; |
| 19112 | |
| 19113 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19114 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 19115 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19116 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19117 | |
| 19118 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 19119 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 19120 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 19121 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 19122 | |
| 19123 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19124 | auto trans1 = |
| 19125 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19126 | |
| 19127 | TestCompletionCallback callback1; |
| 19128 | |
| 19129 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 19130 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19131 | |
| 19132 | std::string response_data; |
| 19133 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19134 | EXPECT_EQ("hello", response_data); |
| 19135 | |
| 19136 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19137 | |
| 19138 | auto trans2 = |
| 19139 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19140 | |
| 19141 | TestCompletionCallback callback2; |
| 19142 | |
| 19143 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 19144 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19145 | |
| 19146 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19147 | EXPECT_EQ("world", response_data); |
| 19148 | |
| 19149 | trans1.reset(); |
| 19150 | trans2.reset(); |
| 19151 | |
| 19152 | // One 200 report from first request, then a 408 report from |
| 19153 | // the second request, then a 200 report from the successful retry. |
| 19154 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19155 | |
| 19156 | // Check error report contents |
| 19157 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19158 | CheckReport(1 /* index */, 408 /* status_code */, OK); |
| 19159 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 19160 | } |
| 19161 | |
| 19162 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19163 | CreateReportRetry421WithoutConnectionPooling) { |
| 19164 | // Two hosts resolve to the same IP address. |
| 19165 | const std::string ip_addr = "1.2.3.4"; |
| 19166 | IPAddress ip; |
| 19167 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 19168 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 19169 | |
| 19170 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
| 19171 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 19172 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 19173 | |
| 19174 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19175 | |
| 19176 | // Two requests on the first connection. |
| 19177 | spdy::SpdySerializedFrame req1( |
| 19178 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 19179 | spdy_util_.UpdateWithStreamDestruction(1); |
| 19180 | spdy::SpdySerializedFrame req2( |
| 19181 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 19182 | spdy::SpdySerializedFrame rst( |
| 19183 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
| 19184 | MockWrite writes1[] = { |
| 19185 | CreateMockWrite(req1, 0), |
| 19186 | CreateMockWrite(req2, 3), |
| 19187 | CreateMockWrite(rst, 6), |
| 19188 | }; |
| 19189 | |
| 19190 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 19191 | spdy::SpdySerializedFrame resp1( |
| 19192 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 19193 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 19194 | spdy::SpdyHeaderBlock response_headers; |
| 19195 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 19196 | spdy::SpdySerializedFrame resp2( |
| 19197 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 19198 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 19199 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 19200 | |
| 19201 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 19202 | SequencedSocketData data1(connect1, reads1, writes1); |
| 19203 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19204 | |
| 19205 | AddSSLSocketData(); |
| 19206 | |
| 19207 | // Retry the second request on a second connection. |
| 19208 | SpdyTestUtil spdy_util2; |
| 19209 | spdy::SpdySerializedFrame req3( |
| 19210 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 19211 | MockWrite writes2[] = { |
| 19212 | CreateMockWrite(req3, 0), |
| 19213 | }; |
| 19214 | |
| 19215 | spdy::SpdySerializedFrame resp3( |
| 19216 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 19217 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 19218 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 19219 | MockRead(ASYNC, 0, 3)}; |
| 19220 | |
| 19221 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 19222 | SequencedSocketData data2(connect2, reads2, writes2); |
| 19223 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19224 | |
| 19225 | AddSSLSocketData(); |
| 19226 | |
| 19227 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 19228 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 19229 | HostPortPair("mail.example.com", 443), base::nullopt); |
| 19230 | EXPECT_THAT(rv, IsOk()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19231 | |
| 19232 | HttpRequestInfo request1; |
| 19233 | request1.method = "GET"; |
| 19234 | request1.url = GURL("https://www.example.org/"); |
| 19235 | request1.load_flags = 0; |
| 19236 | request1.traffic_annotation = |
| 19237 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19238 | auto trans1 = |
| 19239 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19240 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 19241 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19242 | rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 19243 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19244 | |
| 19245 | const HttpResponseInfo* response = trans1->GetResponseInfo(); |
| 19246 | ASSERT_TRUE(response); |
| 19247 | ASSERT_TRUE(response->headers); |
| 19248 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19249 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19250 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19251 | std::string response_data; |
| 19252 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19253 | EXPECT_EQ("hello!", response_data); |
| 19254 | |
| 19255 | trans1.reset(); |
| 19256 | |
| 19257 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19258 | |
| 19259 | HttpRequestInfo request2; |
| 19260 | request2.method = "GET"; |
| 19261 | request2.url = GURL("https://mail.example.org/"); |
| 19262 | request2.load_flags = 0; |
| 19263 | request2.traffic_annotation = |
| 19264 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19265 | auto trans2 = |
| 19266 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19267 | |
| 19268 | BoundTestNetLog log; |
| 19269 | rv = trans2->Start(&request2, callback.callback(), log.bound()); |
| 19270 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19271 | |
| 19272 | response = trans2->GetResponseInfo(); |
| 19273 | ASSERT_TRUE(response); |
| 19274 | ASSERT_TRUE(response->headers); |
| 19275 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19276 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19277 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19278 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19279 | EXPECT_EQ("hello!", response_data); |
| 19280 | |
| 19281 | trans2.reset(); |
| 19282 | |
| 19283 | // One 200 report from the first request, then a 421 report from the |
| 19284 | // second request, then a 200 report from the successful retry. |
| 19285 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19286 | |
| 19287 | // Check error report contents |
| 19288 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 19289 | network_error_logging_service()->errors()[0]; |
| 19290 | EXPECT_EQ(GURL("https://www.example.org/"), error1.uri); |
| 19291 | EXPECT_TRUE(error1.referrer.is_empty()); |
| 19292 | EXPECT_EQ("", error1.user_agent); |
| 19293 | EXPECT_EQ(ip, error1.server_ip); |
| 19294 | EXPECT_EQ("h2", error1.protocol); |
| 19295 | EXPECT_EQ("GET", error1.method); |
| 19296 | EXPECT_EQ(200, error1.status_code); |
| 19297 | EXPECT_EQ(OK, error1.type); |
| 19298 | EXPECT_EQ(0, error1.reporting_upload_depth); |
| 19299 | |
| 19300 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 19301 | network_error_logging_service()->errors()[1]; |
| 19302 | EXPECT_EQ(GURL("https://mail.example.org/"), error2.uri); |
| 19303 | EXPECT_TRUE(error2.referrer.is_empty()); |
| 19304 | EXPECT_EQ("", error2.user_agent); |
| 19305 | EXPECT_EQ(ip, error2.server_ip); |
| 19306 | EXPECT_EQ("h2", error2.protocol); |
| 19307 | EXPECT_EQ("GET", error2.method); |
| 19308 | EXPECT_EQ(421, error2.status_code); |
| 19309 | EXPECT_EQ(OK, error2.type); |
| 19310 | EXPECT_EQ(0, error2.reporting_upload_depth); |
| 19311 | |
| 19312 | const NetworkErrorLoggingService::RequestDetails& error3 = |
| 19313 | network_error_logging_service()->errors()[2]; |
| 19314 | EXPECT_EQ(GURL("https://mail.example.org/"), error3.uri); |
| 19315 | EXPECT_TRUE(error3.referrer.is_empty()); |
| 19316 | EXPECT_EQ("", error3.user_agent); |
| 19317 | EXPECT_EQ(ip, error3.server_ip); |
| 19318 | EXPECT_EQ("h2", error3.protocol); |
| 19319 | EXPECT_EQ("GET", error3.method); |
| 19320 | EXPECT_EQ(200, error3.status_code); |
| 19321 | EXPECT_EQ(OK, error3.type); |
| 19322 | EXPECT_EQ(0, error3.reporting_upload_depth); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19323 | } |
| 19324 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19325 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19326 | CreateReportCancelAfterStart) { |
| 19327 | StaticSocketDataProvider data; |
| 19328 | data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING)); |
| 19329 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19330 | |
| 19331 | TestCompletionCallback callback; |
| 19332 | auto session = CreateSession(&session_deps_); |
| 19333 | auto trans = |
| 19334 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19335 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19336 | EXPECT_EQ(rv, ERR_IO_PENDING); |
| 19337 | |
| 19338 | // Cancel after start. |
| 19339 | trans.reset(); |
| 19340 | |
| 19341 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19342 | CheckReport(0 /* index */, 0 /* status_code */, ERR_ABORTED, |
| 19343 | IPAddress() /* server_ip */); |
| 19344 | } |
| 19345 | |
| 19346 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19347 | CreateReportCancelBeforeReadingBody) { |
| 19348 | std::string extra_header_string = extra_headers_.ToString(); |
| 19349 | MockWrite data_writes[] = { |
| 19350 | MockWrite("GET / HTTP/1.1\r\n" |
| 19351 | "Host: www.example.org\r\n" |
| 19352 | "Connection: keep-alive\r\n"), |
| 19353 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19354 | }; |
| 19355 | MockRead data_reads[] = { |
| 19356 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 19357 | MockRead("Content-Length: 100\r\n\r\n"), // Body is never read. |
| 19358 | }; |
| 19359 | |
| 19360 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19361 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19362 | |
| 19363 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19364 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19365 | |
| 19366 | TestCompletionCallback callback; |
| 19367 | auto session = CreateSession(&session_deps_); |
| 19368 | auto trans = |
| 19369 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19370 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19371 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19372 | |
| 19373 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19374 | ASSERT_TRUE(response); |
| 19375 | |
| 19376 | EXPECT_TRUE(response->headers); |
| 19377 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 19378 | |
| 19379 | // Cancel before reading the body. |
| 19380 | trans.reset(); |
| 19381 | |
| 19382 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19383 | CheckReport(0 /* index */, 200 /* status_code */, ERR_ABORTED); |
| 19384 | } |
| 19385 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19386 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportHttp) { |
| 19387 | base::HistogramTester histograms; |
| 19388 | RequestPolicy(); |
| 19389 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19390 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19391 | |
| 19392 | // Make HTTP request |
| 19393 | std::string extra_header_string = extra_headers_.ToString(); |
| 19394 | MockRead data_reads[] = { |
| 19395 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 19396 | MockRead("hello world"), |
| 19397 | MockRead(SYNCHRONOUS, OK), |
| 19398 | }; |
| 19399 | MockWrite data_writes[] = { |
| 19400 | MockWrite("GET / HTTP/1.1\r\n" |
| 19401 | "Host: www.example.org\r\n" |
| 19402 | "Connection: keep-alive\r\n"), |
| 19403 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19404 | }; |
| 19405 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19406 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19407 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19408 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19409 | // Insecure url |
| 19410 | url_ = "http://www.example.org/"; |
| 19411 | request_.url = GURL(url_); |
| 19412 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19413 | TestCompletionCallback callback; |
| 19414 | auto session = CreateSession(&session_deps_); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19415 | auto trans = |
| 19416 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19417 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19418 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19419 | |
| 19420 | std::string response_data; |
| 19421 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19422 | EXPECT_EQ("hello world", response_data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19423 | |
| 19424 | // Insecure request does not generate a report |
| 19425 | histograms.ExpectBucketCount( |
| 19426 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
Tsuyoshi Horo | 0b04223 | 2019-03-06 01:11:05 | [diff] [blame] | 19427 | NetworkErrorLoggingService::RequestOutcome::kDiscardedInsecureOrigin, 1); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19428 | |
| 19429 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19430 | } |
| 19431 | |
| 19432 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19433 | DontCreateReportHttpError) { |
| 19434 | base::HistogramTester histograms; |
| 19435 | RequestPolicy(); |
| 19436 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19437 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19438 | |
| 19439 | // Make HTTP request that fails |
| 19440 | MockRead data_reads[] = { |
| 19441 | MockRead("hello world"), |
| 19442 | MockRead(SYNCHRONOUS, OK), |
| 19443 | }; |
| 19444 | |
| 19445 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
| 19446 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19447 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19448 | url_ = "http://www.originwithoutpolicy.com:2000/"; |
| 19449 | request_.url = GURL(url_); |
| 19450 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19451 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19452 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19453 | auto trans = |
| 19454 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19455 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19456 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19457 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 19458 | |
| 19459 | // Insecure request does not generate a report, regardless of existence of a |
| 19460 | // policy for the origin. |
| 19461 | histograms.ExpectBucketCount( |
| 19462 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
Tsuyoshi Horo | 0b04223 | 2019-03-06 01:11:05 | [diff] [blame] | 19463 | NetworkErrorLoggingService::RequestOutcome::kDiscardedInsecureOrigin, 1); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19464 | |
| 19465 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19466 | } |
| 19467 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 19468 | // Don't report on proxy auth challenges, don't report if connecting through a |
| 19469 | // proxy. |
| 19470 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportProxy) { |
| 19471 | HttpRequestInfo request; |
| 19472 | request.method = "GET"; |
| 19473 | request.url = GURL("https://www.example.org/"); |
| 19474 | request.traffic_annotation = |
| 19475 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19476 | |
| 19477 | // Configure against proxy server "myproxy:70". |
| 19478 | session_deps_.proxy_resolution_service = |
| 19479 | ProxyResolutionService::CreateFixedFromPacResult( |
| 19480 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19481 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19482 | |
| 19483 | // Since we have proxy, should try to establish tunnel. |
| 19484 | MockWrite data_writes1[] = { |
| 19485 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19486 | "Host: www.example.org:443\r\n" |
| 19487 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 19488 | }; |
| 19489 | |
| 19490 | // The proxy responds to the connect with a 407, using a non-persistent |
| 19491 | // connection. |
| 19492 | MockRead data_reads1[] = { |
| 19493 | // No credentials. |
| 19494 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 19495 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 19496 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 19497 | }; |
| 19498 | |
| 19499 | MockWrite data_writes2[] = { |
| 19500 | // After calling trans->RestartWithAuth(), this is the request we should |
| 19501 | // be issuing -- the final header line contains the credentials. |
| 19502 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19503 | "Host: www.example.org:443\r\n" |
| 19504 | "Proxy-Connection: keep-alive\r\n" |
| 19505 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 19506 | |
| 19507 | MockWrite("GET / HTTP/1.1\r\n" |
| 19508 | "Host: www.example.org\r\n" |
| 19509 | "Connection: keep-alive\r\n\r\n"), |
| 19510 | }; |
| 19511 | |
| 19512 | MockRead data_reads2[] = { |
| 19513 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 19514 | |
| 19515 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19516 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 19517 | MockRead("Content-Length: 5\r\n\r\n"), |
| 19518 | MockRead(SYNCHRONOUS, "hello"), |
| 19519 | }; |
| 19520 | |
| 19521 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19522 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19523 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 19524 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19525 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19526 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19527 | |
| 19528 | TestCompletionCallback callback1; |
| 19529 | |
| 19530 | auto trans = |
| 19531 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19532 | |
| 19533 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
| 19534 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19535 | |
| 19536 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19537 | EXPECT_EQ(407, response->headers->response_code()); |
| 19538 | |
| 19539 | std::string response_data; |
| 19540 | rv = ReadTransaction(trans.get(), &response_data); |
| 19541 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
| 19542 | |
| 19543 | // No NEL report is generated for the 407. |
| 19544 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 19545 | |
| 19546 | TestCompletionCallback callback2; |
| 19547 | |
| 19548 | rv = |
| 19549 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 19550 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19551 | |
| 19552 | response = trans->GetResponseInfo(); |
| 19553 | EXPECT_EQ(200, response->headers->response_code()); |
| 19554 | |
| 19555 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19556 | EXPECT_EQ("hello", response_data); |
| 19557 | |
| 19558 | trans.reset(); |
| 19559 | |
| 19560 | // No NEL report is generated because we are behind a proxy. |
| 19561 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 19562 | } |
| 19563 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19564 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19565 | ReportContainsUploadDepth) { |
| 19566 | reporting_upload_depth_ = 7; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19567 | request_.reporting_upload_depth = reporting_upload_depth_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19568 | RequestPolicy(); |
| 19569 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19570 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19571 | network_error_logging_service()->errors()[0]; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19572 | EXPECT_EQ(7, error.reporting_upload_depth); |
| 19573 | } |
| 19574 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19575 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ReportElapsedTime) { |
| 19576 | std::string extra_header_string = extra_headers_.ToString(); |
| 19577 | static const base::TimeDelta kSleepDuration = |
| 19578 | base::TimeDelta::FromMilliseconds(10); |
| 19579 | |
| 19580 | std::vector<MockWrite> data_writes = { |
| 19581 | MockWrite(ASYNC, 0, |
| 19582 | "GET / HTTP/1.1\r\n" |
| 19583 | "Host: www.example.org\r\n" |
| 19584 | "Connection: keep-alive\r\n"), |
| 19585 | MockWrite(ASYNC, 1, extra_header_string.data()), |
| 19586 | }; |
| 19587 | |
| 19588 | std::vector<MockRead> data_reads = { |
| 19589 | // Write one byte of the status line, followed by a pause. |
| 19590 | MockRead(ASYNC, 2, "H"), |
| 19591 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 19592 | MockRead(ASYNC, 4, "TTP/1.1 200 OK\r\n\r\n"), |
| 19593 | MockRead(ASYNC, 5, "hello world"), |
| 19594 | MockRead(SYNCHRONOUS, OK, 6), |
| 19595 | }; |
| 19596 | |
| 19597 | SequencedSocketData data(data_reads, data_writes); |
| 19598 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19599 | |
| 19600 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19601 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19602 | |
| 19603 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19604 | |
| 19605 | auto trans = |
| 19606 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19607 | |
| 19608 | TestCompletionCallback callback; |
| 19609 | |
| 19610 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19611 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19612 | |
| 19613 | data.RunUntilPaused(); |
| 19614 | ASSERT_TRUE(data.IsPaused()); |
| 19615 | FastForwardBy(kSleepDuration); |
| 19616 | data.Resume(); |
| 19617 | |
| 19618 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19619 | |
| 19620 | std::string response_data; |
| 19621 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19622 | EXPECT_EQ("hello world", response_data); |
| 19623 | |
| 19624 | trans.reset(); |
| 19625 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19626 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19627 | |
| 19628 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19629 | |
| 19630 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19631 | network_error_logging_service()->errors()[0]; |
| 19632 | |
| 19633 | // Sanity-check elapsed time in error report |
| 19634 | EXPECT_EQ(kSleepDuration, error.elapsed_time); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19635 | } |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19636 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19637 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 19638 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 19639 | } // namespace net |