[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" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 98 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 99 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 100 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 101 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 102 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 103 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 104 | #include "net/test/test_data_directory.h" |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 105 | #include "net/test/test_with_scoped_task_environment.h" |
Victor Vasiliev | 27cc771 | 2019-01-24 11:50:14 | [diff] [blame] | 106 | #include "net/third_party/quiche/src/spdy/core/spdy_framer.h" |
[email protected] | baee31a | 2018-01-18 06:10:23 | [diff] [blame] | 107 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 108 | #include "net/url_request/static_http_user_agent_settings.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 109 | #include "net/websockets/websocket_handshake_stream_base.h" |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 110 | #include "net/websockets/websocket_test_util.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 111 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 112 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 113 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 114 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 115 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 116 | #if defined(NTLM_PORTABLE) |
| 117 | #include "base/base64.h" |
| 118 | #include "net/ntlm/ntlm_test_data.h" |
| 119 | #endif |
| 120 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 121 | #if BUILDFLAG(ENABLE_REPORTING) |
| 122 | #include "net/network_error_logging/network_error_logging_service.h" |
| 123 | #include "net/network_error_logging/network_error_logging_test_util.h" |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 124 | #include "net/reporting/reporting_cache.h" |
| 125 | #include "net/reporting/reporting_client.h" |
| 126 | #include "net/reporting/reporting_header_parser.h" |
| 127 | #include "net/reporting/reporting_service.h" |
| 128 | #include "net/reporting/reporting_test_util.h" |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 129 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 130 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 131 | using net::test::IsError; |
| 132 | using net::test::IsOk; |
| 133 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 134 | using base::ASCIIToUTF16; |
| 135 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 136 | //----------------------------------------------------------------------------- |
| 137 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 138 | namespace net { |
| 139 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 140 | namespace { |
| 141 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 142 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 143 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 144 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 145 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 146 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 147 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 148 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 149 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 150 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 151 | const base::string16 kSecond(ASCIIToUTF16("second")); |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 152 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 153 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 154 | const char kAlternativeServiceHttpHeader[] = |
| 155 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 156 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 157 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 158 | return session |
| 159 | ->GetSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 160 | ProxyServer::Direct()) |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 161 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 162 | } |
| 163 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 164 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 165 | return session |
| 166 | ->GetSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 167 | ProxyServer::Direct()) |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 168 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 169 | } |
| 170 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 171 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 172 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 173 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 174 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 175 | if (!params) |
| 176 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 177 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 178 | if (!params->GetList("headers", &header_list)) |
| 179 | return false; |
| 180 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 181 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 182 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 183 | return true; |
| 184 | } |
| 185 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 186 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 187 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 188 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 189 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 190 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 191 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 192 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 193 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 194 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 195 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 196 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 197 | |
| 198 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 199 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 200 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 201 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 202 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 203 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 204 | } |
| 205 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 206 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 207 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 208 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 209 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 210 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 211 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 212 | |
| 213 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 214 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 215 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 216 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 217 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 218 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 219 | load_timing_info.send_start); |
| 220 | |
| 221 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 222 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 223 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 224 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 225 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 226 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 230 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 231 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 232 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 233 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 234 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 235 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 236 | |
| 237 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 238 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 239 | load_timing_info.proxy_resolve_end); |
| 240 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 241 | load_timing_info.send_start); |
| 242 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 243 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 244 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 245 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 246 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 247 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 251 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 252 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 253 | int connect_timing_flags) { |
| 254 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 255 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 256 | |
| 257 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 258 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 259 | load_timing_info.proxy_resolve_end); |
| 260 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 261 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 262 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 263 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 264 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 265 | load_timing_info.send_start); |
| 266 | |
| 267 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 268 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 269 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 270 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 271 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 272 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 273 | } |
| 274 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 275 | // ProxyResolver that records URLs passed to it, and that can be told what |
| 276 | // result to return. |
| 277 | class CapturingProxyResolver : public ProxyResolver { |
| 278 | public: |
| 279 | CapturingProxyResolver() |
| 280 | : proxy_server_(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 80)) {} |
| 281 | ~CapturingProxyResolver() override = default; |
| 282 | |
| 283 | int GetProxyForURL(const GURL& url, |
| 284 | ProxyInfo* results, |
| 285 | CompletionOnceCallback callback, |
| 286 | std::unique_ptr<Request>* request, |
| 287 | const NetLogWithSource& net_log) override { |
| 288 | results->UseProxyServer(proxy_server_); |
| 289 | resolved_.push_back(url); |
| 290 | return OK; |
| 291 | } |
| 292 | |
| 293 | // Sets whether the resolver should use direct connections, instead of a |
| 294 | // proxy. |
| 295 | void set_proxy_server(ProxyServer proxy_server) { |
| 296 | proxy_server_ = proxy_server; |
| 297 | } |
| 298 | |
| 299 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 300 | |
| 301 | private: |
| 302 | std::vector<GURL> resolved_; |
| 303 | |
| 304 | ProxyServer proxy_server_; |
| 305 | |
| 306 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 307 | }; |
| 308 | |
| 309 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 310 | public: |
| 311 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 312 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 313 | |
| 314 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 315 | std::unique_ptr<ProxyResolver>* resolver, |
| 316 | CompletionOnceCallback callback, |
| 317 | std::unique_ptr<Request>* request) override { |
| 318 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
| 319 | return OK; |
| 320 | } |
| 321 | |
| 322 | private: |
| 323 | ProxyResolver* resolver_; |
| 324 | }; |
| 325 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 326 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 327 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 328 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 329 | } |
| 330 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 331 | class FailingProxyResolverFactory : public ProxyResolverFactory { |
| 332 | public: |
| 333 | FailingProxyResolverFactory() : ProxyResolverFactory(false) {} |
| 334 | |
| 335 | // ProxyResolverFactory override. |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 336 | int CreateProxyResolver(const scoped_refptr<PacFileData>& script_data, |
| 337 | std::unique_ptr<ProxyResolver>* result, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 338 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 339 | std::unique_ptr<Request>* request) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 340 | return ERR_PAC_SCRIPT_FAILED; |
| 341 | } |
| 342 | }; |
| 343 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 344 | class TestSSLConfigService : public SSLConfigService { |
| 345 | public: |
| 346 | explicit TestSSLConfigService(const SSLConfig& config) : config_(config) {} |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 347 | ~TestSSLConfigService() override = default; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 348 | |
| 349 | void GetSSLConfig(SSLConfig* config) override { *config = config_; } |
| 350 | |
Nick Harper | 89bc721 | 2018-07-31 19:07:57 | [diff] [blame] | 351 | bool CanShareConnectionWithClientCerts( |
| 352 | const std::string& hostname) const override { |
| 353 | return false; |
| 354 | } |
| 355 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 356 | private: |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 357 | SSLConfig config_; |
| 358 | }; |
| 359 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 360 | } // namespace |
| 361 | |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 362 | class HttpNetworkTransactionTest : public PlatformTest, |
| 363 | public WithScopedTaskEnvironment { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 364 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 365 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 366 | // Important to restore the per-pool limit first, since the pool limit must |
| 367 | // always be greater than group limit, and the tests reduce both limits. |
| 368 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 369 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 370 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 371 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 372 | } |
| 373 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 374 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 375 | HttpNetworkTransactionTest() |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 376 | : WithScopedTaskEnvironment( |
| 377 | base::test::ScopedTaskEnvironment::MainThreadType::IO_MOCK_TIME, |
| 378 | base::test::ScopedTaskEnvironment::NowSource:: |
| 379 | MAIN_THREAD_MOCK_TIME), |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 380 | dummy_connect_job_params_( |
| 381 | nullptr /* client_socket_factory */, |
| 382 | nullptr /* host_resolver */, |
Matt Menke | b88837e | 2019-03-20 11:50:40 | [diff] [blame] | 383 | nullptr /* http_auth_cache */, |
| 384 | nullptr /* http_auth_handler_factory */, |
| 385 | nullptr /* spdy_session_pool */, |
Matt Menke | b5fb42b | 2019-03-22 17:26:13 | [diff] [blame] | 386 | nullptr /* quic_supported_versions */, |
Matt Menke | b88837e | 2019-03-20 11:50:40 | [diff] [blame] | 387 | nullptr /* quic_stream_factory */, |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 388 | nullptr /* proxy_delegate */, |
| 389 | nullptr /* http_user_agent_settings */, |
| 390 | SSLClientSocketContext(), |
| 391 | SSLClientSocketContext(), |
| 392 | nullptr /* socket_performance_watcher_factory */, |
| 393 | nullptr /* network_quality_estimator */, |
| 394 | nullptr /* net_log */, |
| 395 | nullptr /* websocket_endpoint_lock_manager */), |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 396 | ssl_(ASYNC, OK), |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 397 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 398 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 399 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 400 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 401 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 402 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 403 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 404 | struct SimpleGetHelperResult { |
| 405 | int rv; |
| 406 | std::string status_line; |
| 407 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 408 | int64_t total_received_bytes; |
| 409 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 410 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 411 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 412 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 413 | }; |
| 414 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 415 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 416 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 417 | base::RunLoop().RunUntilIdle(); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 418 | // Set an initial delay to ensure that the first call to TimeTicks::Now() |
| 419 | // before incrementing the counter does not return a null value. |
| 420 | FastForwardBy(TimeDelta::FromSeconds(1)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 421 | } |
| 422 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 423 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 424 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 425 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 426 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 427 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 428 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 429 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 430 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 431 | } |
| 432 | |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 433 | void Check100ResponseTiming(bool use_spdy); |
| 434 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 435 | // Either |write_failure| specifies a write failure or |read_failure| |
| 436 | // specifies a read failure when using a reused socket. In either case, the |
| 437 | // failure should cause the network transaction to resend the request, and the |
| 438 | // other argument should be NULL. |
| 439 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 440 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 441 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 442 | // Either |write_failure| specifies a write failure or |read_failure| |
| 443 | // specifies a read failure when using a reused socket. In either case, the |
| 444 | // failure should cause the network transaction to resend the request, and the |
| 445 | // other argument should be NULL. |
| 446 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 447 | const MockRead* read_failure, |
| 448 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 449 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 450 | SimpleGetHelperResult SimpleGetHelperForData( |
| 451 | base::span<StaticSocketDataProvider*> providers) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 452 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 453 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 454 | HttpRequestInfo request; |
| 455 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 456 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 457 | request.traffic_annotation = |
| 458 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 459 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 460 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 461 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 462 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 463 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 464 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 465 | for (auto* provider : providers) { |
| 466 | session_deps_.socket_factory->AddSocketDataProvider(provider); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 467 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 468 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 469 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 470 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 471 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 472 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 473 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 474 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 475 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 476 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 477 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 478 | |
| 479 | // Even in the failure cases that use this function, connections are always |
| 480 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 481 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 482 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 483 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 484 | if (out.rv != OK) |
| 485 | return out; |
| 486 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 487 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 488 | // Can't use ASSERT_* inside helper functions like this, so |
| 489 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 490 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 491 | out.rv = ERR_UNEXPECTED; |
| 492 | return out; |
| 493 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 494 | out.status_line = response->headers->GetStatusLine(); |
| 495 | |
Tsuyoshi Horo | 01faed6 | 2019-02-20 22:11:37 | [diff] [blame] | 496 | EXPECT_EQ("127.0.0.1", response->remote_endpoint.ToStringWithoutPort()); |
| 497 | EXPECT_EQ(80, response->remote_endpoint.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 498 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 499 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 500 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 501 | EXPECT_EQ(got_endpoint, |
| 502 | out.remote_endpoint_after_start.address().size() > 0); |
| 503 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 504 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 505 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 506 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 507 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 508 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 509 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 510 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 511 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 512 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 513 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 514 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 515 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 516 | std::string line; |
| 517 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 518 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 519 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 520 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 521 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 522 | std::string value; |
| 523 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 524 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 525 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 526 | EXPECT_EQ("keep-alive", value); |
| 527 | |
| 528 | std::string response_headers; |
| 529 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 530 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 531 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 532 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 533 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 534 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 535 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 536 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 537 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 538 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 539 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 540 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 541 | SimpleGetHelperResult SimpleGetHelper(base::span<const MockRead> data_reads) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 542 | MockWrite data_writes[] = { |
| 543 | MockWrite("GET / HTTP/1.1\r\n" |
| 544 | "Host: www.example.org\r\n" |
| 545 | "Connection: keep-alive\r\n\r\n"), |
| 546 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 547 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 548 | StaticSocketDataProvider reads(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 549 | StaticSocketDataProvider* data[] = {&reads}; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 550 | SimpleGetHelperResult out = SimpleGetHelperForData(data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 551 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 552 | EXPECT_EQ(CountWriteBytes(data_writes), out.total_sent_bytes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 553 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 554 | } |
| 555 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 556 | void AddSSLSocketData() { |
| 557 | ssl_.next_proto = kProtoHTTP2; |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 558 | ssl_.ssl_info.cert = |
| 559 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 560 | ASSERT_TRUE(ssl_.ssl_info.cert); |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 561 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 562 | } |
| 563 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 564 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 565 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 566 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 567 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 568 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 569 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 570 | |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 571 | const CommonConnectJobParams dummy_connect_job_params_; |
| 572 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 573 | // These clocks are defined here, even though they're only used in the |
| 574 | // Reporting tests below, since they need to be destroyed after |
| 575 | // |session_deps_|. |
| 576 | base::SimpleTestClock clock_; |
| 577 | base::SimpleTestTickClock tick_clock_; |
| 578 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 579 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 580 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 581 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 582 | |
| 583 | // Original socket limits. Some tests set these. Safest to always restore |
| 584 | // them once each test has been run. |
| 585 | int old_max_group_sockets_; |
| 586 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 587 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 588 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 589 | namespace { |
| 590 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 591 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 592 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 593 | BeforeHeadersSentHandler() |
| 594 | : observed_before_headers_sent_with_proxy_(false), |
| 595 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 596 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 597 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 598 | HttpRequestHeaders* request_headers) { |
| 599 | observed_before_headers_sent_ = true; |
| 600 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 601 | !proxy_info.is_quic()) { |
| 602 | return; |
| 603 | } |
| 604 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 605 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 606 | } |
| 607 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 608 | bool observed_before_headers_sent_with_proxy() const { |
| 609 | return observed_before_headers_sent_with_proxy_; |
| 610 | } |
| 611 | |
| 612 | bool observed_before_headers_sent() const { |
| 613 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | std::string observed_proxy_server_uri() const { |
| 617 | return observed_proxy_server_uri_; |
| 618 | } |
| 619 | |
| 620 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 621 | bool observed_before_headers_sent_with_proxy_; |
| 622 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 623 | std::string observed_proxy_server_uri_; |
| 624 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 625 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 626 | }; |
| 627 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 628 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 629 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 630 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 631 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 632 | const int sizeof_row = strlen(row); |
| 633 | const int num_rows = static_cast<int>( |
| 634 | ceil(static_cast<float>(size) / sizeof_row)); |
| 635 | const int sizeof_data = num_rows * sizeof_row; |
| 636 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 637 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 638 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 639 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 640 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 641 | } |
| 642 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 643 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 644 | uint64_t MockGetMSTime() { |
| 645 | // Tue, 23 May 2017 20:13:07 +0000 |
| 646 | return 131400439870000000; |
| 647 | } |
| 648 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 649 | // Alternative functions that eliminate randomness and dependency on the local |
| 650 | // host name so that the generated NTLM messages are reproducible. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 651 | void MockGenerateRandom(uint8_t* output, size_t n) { |
| 652 | // This is set to 0xaa because the client challenge for testing in |
| 653 | // [MS-NLMP] Section 4.2.1 is 8 bytes of 0xaa. |
| 654 | memset(output, 0xaa, n); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 655 | } |
| 656 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 657 | std::string MockGetHostName() { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 658 | return ntlm::test::kHostnameAscii; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 659 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 660 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 661 | |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 662 | class CaptureGroupIdTransportSocketPool : public TransportClientSocketPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 663 | public: |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 664 | explicit CaptureGroupIdTransportSocketPool( |
| 665 | const CommonConnectJobParams* common_connect_job_params) |
| 666 | : TransportClientSocketPool(0, |
| 667 | 0, |
| 668 | base::TimeDelta(), |
| 669 | common_connect_job_params, |
| 670 | nullptr /* ssl_config_service */) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 671 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 672 | const ClientSocketPool::GroupId& last_group_id_received() const { |
| 673 | return last_group_id_; |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 674 | } |
| 675 | |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 676 | bool socket_requested() const { return socket_requested_; } |
| 677 | |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 678 | int RequestSocket( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 679 | const ClientSocketPool::GroupId& group_id, |
Matt Menke | bd12b7e | 2019-03-25 21:12:03 | [diff] [blame] | 680 | scoped_refptr<ClientSocketPool::SocketParams> socket_params, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 681 | RequestPriority priority, |
| 682 | const SocketTag& socket_tag, |
| 683 | ClientSocketPool::RespectLimits respect_limits, |
| 684 | ClientSocketHandle* handle, |
| 685 | CompletionOnceCallback callback, |
| 686 | const ClientSocketPool::ProxyAuthCallback& proxy_auth_callback, |
| 687 | const NetLogWithSource& net_log) override { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 688 | last_group_id_ = group_id; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 689 | socket_requested_ = true; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 690 | return ERR_IO_PENDING; |
| 691 | } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 692 | void CancelRequest(const ClientSocketPool::GroupId& group_id, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 693 | ClientSocketHandle* handle) override {} |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 694 | void ReleaseSocket(const ClientSocketPool::GroupId& group_id, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 695 | std::unique_ptr<StreamSocket> socket, |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 696 | int64_t generation) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 697 | void CloseIdleSockets() override {} |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 698 | void CloseIdleSocketsInGroup( |
| 699 | const ClientSocketPool::GroupId& group_id) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 700 | int IdleSocketCount() const override { return 0; } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 701 | size_t IdleSocketCountInGroup( |
| 702 | const ClientSocketPool::GroupId& group_id) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 703 | return 0; |
| 704 | } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 705 | LoadState GetLoadState(const ClientSocketPool::GroupId& group_id, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 706 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 707 | return LOAD_STATE_IDLE; |
| 708 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 709 | |
| 710 | private: |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 711 | ClientSocketPool::GroupId last_group_id_; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 712 | bool socket_requested_ = false; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 713 | }; |
| 714 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 715 | //----------------------------------------------------------------------------- |
| 716 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 717 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 718 | // configured for common cases. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 719 | bool CheckBasicServerAuth( |
| 720 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 721 | if (!auth_challenge) |
| 722 | return false; |
| 723 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 724 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 725 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 726 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 727 | return true; |
| 728 | } |
| 729 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 730 | bool CheckBasicProxyAuth( |
| 731 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 732 | if (!auth_challenge) |
| 733 | return false; |
| 734 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 735 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 736 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 737 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 738 | return true; |
| 739 | } |
| 740 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 741 | bool CheckBasicSecureProxyAuth( |
| 742 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 743 | if (!auth_challenge) |
| 744 | return false; |
| 745 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 746 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 747 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 748 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 749 | return true; |
| 750 | } |
| 751 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 752 | bool CheckDigestServerAuth( |
| 753 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 754 | if (!auth_challenge) |
| 755 | return false; |
| 756 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 757 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 758 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 759 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 760 | return true; |
| 761 | } |
| 762 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 763 | #if defined(NTLM_PORTABLE) |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 764 | bool CheckNTLMServerAuth( |
| 765 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 766 | if (!auth_challenge) |
| 767 | return false; |
| 768 | EXPECT_FALSE(auth_challenge->is_proxy); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 769 | EXPECT_EQ("https://server", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 770 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 771 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 772 | return true; |
| 773 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 774 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 775 | bool CheckNTLMProxyAuth( |
| 776 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 777 | if (!auth_challenge) |
| 778 | return false; |
| 779 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 780 | EXPECT_EQ("http://server", auth_challenge->challenger.Serialize()); |
| 781 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 782 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
| 783 | return true; |
| 784 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 785 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 786 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 787 | } // namespace |
| 788 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 789 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 790 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 791 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 792 | } |
| 793 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 794 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 795 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 796 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 797 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 798 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 799 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 800 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 801 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 802 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 803 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 804 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 805 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 806 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 807 | |
| 808 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 812 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 813 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 814 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 815 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 816 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 817 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 818 | EXPECT_THAT(out.rv, IsOk()); |
| 819 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 820 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 821 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 822 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 823 | } |
| 824 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 825 | // Response with no status line, and a weird port. Should fail by default. |
| 826 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 827 | MockRead data_reads[] = { |
| 828 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 829 | }; |
| 830 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 831 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 832 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 833 | |
| 834 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 835 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 836 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 837 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 838 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 839 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 840 | request.method = "GET"; |
| 841 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 842 | request.traffic_annotation = |
| 843 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 844 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 845 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 846 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 847 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 848 | } |
| 849 | |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 850 | // Tests that request info can be destroyed after the headers phase is complete. |
| 851 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoReadDestroyRequestInfo) { |
| 852 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 853 | auto trans = |
| 854 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 855 | |
| 856 | MockRead data_reads[] = { |
| 857 | MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Connection: keep-alive\r\n"), |
| 858 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, 0), |
| 859 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 860 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 861 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 862 | |
| 863 | TestCompletionCallback callback; |
| 864 | |
| 865 | { |
| 866 | auto request = std::make_unique<HttpRequestInfo>(); |
| 867 | request->method = "GET"; |
| 868 | request->url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 869 | request->traffic_annotation = |
| 870 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 871 | |
| 872 | int rv = |
| 873 | trans->Start(request.get(), callback.callback(), NetLogWithSource()); |
| 874 | |
| 875 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 876 | } // Let request info be destroyed. |
| 877 | |
| 878 | trans.reset(); |
| 879 | } |
| 880 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 881 | // Response with no status line, and a weird port. Option to allow weird ports |
| 882 | // enabled. |
| 883 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 884 | MockRead data_reads[] = { |
| 885 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 886 | }; |
| 887 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 888 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 889 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 890 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 891 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 892 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 893 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 894 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 895 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 896 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 897 | request.method = "GET"; |
| 898 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 899 | request.traffic_annotation = |
| 900 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 901 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 902 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 903 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 904 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 905 | |
| 906 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 907 | ASSERT_TRUE(info->headers); |
| 908 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 909 | |
| 910 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 911 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 912 | } |
| 913 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 914 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 915 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 916 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 917 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 918 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 919 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 920 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 921 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 922 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 923 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 924 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 925 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 929 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 930 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 931 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 932 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 933 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 934 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 935 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 936 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 937 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 938 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 939 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 943 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 944 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 945 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 946 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 947 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 948 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 949 | EXPECT_THAT(out.rv, IsOk()); |
| 950 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 951 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 952 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 953 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 957 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 958 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 959 | MockRead("\n"), |
| 960 | MockRead("\n"), |
| 961 | MockRead("Q"), |
| 962 | MockRead("J"), |
| 963 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 964 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 965 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 966 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 967 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 968 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 969 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 970 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 971 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 975 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 976 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 977 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 978 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 979 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 980 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 981 | EXPECT_THAT(out.rv, IsOk()); |
| 982 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 983 | EXPECT_EQ("HTT", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 984 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 985 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 986 | } |
| 987 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 988 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 989 | // persistent connection. The response should still terminate since a 204 |
| 990 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 991 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 992 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 993 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 994 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 995 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 996 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 997 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 998 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 999 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1000 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 1001 | EXPECT_EQ("", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1002 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1003 | int64_t response_size = reads_size - strlen(junk); |
| 1004 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1005 | } |
| 1006 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1007 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1008 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1009 | std::string final_chunk = "0\r\n\r\n"; |
| 1010 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 1011 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1012 | MockRead data_reads[] = { |
| 1013 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 1014 | MockRead("5\r\nHello\r\n"), |
| 1015 | MockRead("1\r\n"), |
| 1016 | MockRead(" \r\n"), |
| 1017 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1018 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1019 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1020 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1021 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1022 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1023 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1024 | EXPECT_EQ("Hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1025 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1026 | int64_t response_size = reads_size - extra_data.size(); |
| 1027 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1028 | } |
| 1029 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1030 | // Next tests deal with http://crbug.com/56344. |
| 1031 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1032 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1033 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 1034 | MockRead data_reads[] = { |
| 1035 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1036 | MockRead("Content-Length: 10\r\n"), |
| 1037 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1038 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1039 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1040 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1041 | } |
| 1042 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1043 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1044 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 1045 | MockRead data_reads[] = { |
| 1046 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1047 | MockRead("Content-Length: 5\r\n"), |
| 1048 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1049 | MockRead("Hello"), |
| 1050 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1051 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1052 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1053 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1054 | EXPECT_EQ("Hello", out.response_data); |
| 1055 | } |
| 1056 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1057 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1058 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1059 | // More than 2 dupes. |
| 1060 | { |
| 1061 | MockRead data_reads[] = { |
| 1062 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1063 | MockRead("Content-Length: 5\r\n"), |
| 1064 | MockRead("Content-Length: 5\r\n"), |
| 1065 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1066 | MockRead("Hello"), |
| 1067 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1068 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1069 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1070 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1071 | EXPECT_EQ("Hello", out.response_data); |
| 1072 | } |
| 1073 | // HTTP/1.0 |
| 1074 | { |
| 1075 | MockRead data_reads[] = { |
| 1076 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1077 | MockRead("Content-Length: 5\r\n"), |
| 1078 | MockRead("Content-Length: 5\r\n"), |
| 1079 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1080 | MockRead("Hello"), |
| 1081 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1082 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1083 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1084 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1085 | EXPECT_EQ("Hello", out.response_data); |
| 1086 | } |
| 1087 | // 2 dupes and one mismatched. |
| 1088 | { |
| 1089 | MockRead data_reads[] = { |
| 1090 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1091 | MockRead("Content-Length: 10\r\n"), |
| 1092 | MockRead("Content-Length: 10\r\n"), |
| 1093 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1094 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1095 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1096 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1097 | } |
| 1098 | } |
| 1099 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1100 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1101 | MultipleContentLengthHeadersTransferEncoding) { |
| 1102 | MockRead data_reads[] = { |
| 1103 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1104 | MockRead("Content-Length: 666\r\n"), |
| 1105 | MockRead("Content-Length: 1337\r\n"), |
| 1106 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1107 | MockRead("5\r\nHello\r\n"), |
| 1108 | MockRead("1\r\n"), |
| 1109 | MockRead(" \r\n"), |
| 1110 | MockRead("5\r\nworld\r\n"), |
| 1111 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1112 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1113 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1114 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1115 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1116 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1117 | EXPECT_EQ("Hello world", out.response_data); |
| 1118 | } |
| 1119 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1120 | // Next tests deal with http://crbug.com/98895. |
| 1121 | |
| 1122 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1123 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1124 | MockRead data_reads[] = { |
| 1125 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1126 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1127 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1128 | MockRead("Hello"), |
| 1129 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1130 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1131 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1132 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1133 | EXPECT_EQ("Hello", out.response_data); |
| 1134 | } |
| 1135 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1136 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1137 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1138 | MockRead data_reads[] = { |
| 1139 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1140 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1141 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1142 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1143 | MockRead("Hello"), |
| 1144 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1145 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1146 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1147 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1148 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1152 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1153 | MockRead data_reads[] = { |
| 1154 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1155 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1156 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1157 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1158 | MockRead("Hello"), |
| 1159 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1160 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1161 | EXPECT_THAT(out.rv, |
| 1162 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1163 | } |
| 1164 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1165 | // Checks that two identical Location headers result in no error. |
| 1166 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1167 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1168 | MockRead data_reads[] = { |
| 1169 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1170 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1171 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1172 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1173 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1174 | }; |
| 1175 | |
| 1176 | HttpRequestInfo request; |
| 1177 | request.method = "GET"; |
| 1178 | request.url = GURL("http://redirect.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1179 | request.traffic_annotation = |
| 1180 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1181 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1182 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1183 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1184 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1185 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1186 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1187 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1188 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1189 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1190 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1191 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1192 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1193 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1194 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1195 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1196 | ASSERT_TRUE(response); |
| 1197 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1198 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1199 | std::string url; |
| 1200 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1201 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1202 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1203 | } |
| 1204 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1205 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1206 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1207 | MockRead data_reads[] = { |
| 1208 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1209 | MockRead("Location: http://good.com/\r\n"), |
| 1210 | MockRead("Location: http://evil.com/\r\n"), |
| 1211 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1212 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1213 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1214 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1215 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1216 | } |
| 1217 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1218 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1219 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1220 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1221 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1222 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1223 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1224 | request.traffic_annotation = |
| 1225 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1226 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1227 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1228 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1229 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1230 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1231 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1232 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1233 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1234 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1235 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1236 | "Host: www.example.org\r\n" |
| 1237 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1238 | }; |
| 1239 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1240 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1241 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1242 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1243 | // No response body because the test stops reading here. |
| 1244 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1245 | }; |
| 1246 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1247 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1248 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1249 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1250 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1251 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1252 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1253 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1254 | |
| 1255 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1256 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1257 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1258 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1259 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1260 | |
| 1261 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1262 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1263 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1264 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1265 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1266 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1267 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1268 | |
| 1269 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1270 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1271 | bool has_server_header = response->headers->EnumerateHeader( |
| 1272 | &iter, "Server", &server_header); |
| 1273 | EXPECT_TRUE(has_server_header); |
| 1274 | EXPECT_EQ("Blah", server_header); |
| 1275 | |
| 1276 | // Reading should give EOF right away, since there is no message body |
| 1277 | // (despite non-zero content-length). |
| 1278 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1279 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1280 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1281 | EXPECT_EQ("", response_data); |
| 1282 | } |
| 1283 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1284 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1285 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1286 | |
| 1287 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1288 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1289 | MockRead("hello"), |
| 1290 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1291 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1292 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1293 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1294 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1295 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1296 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1297 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1298 | "hello", "world" |
| 1299 | }; |
| 1300 | |
| 1301 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1302 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1303 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1304 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1305 | request.traffic_annotation = |
| 1306 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1307 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1308 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1309 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1310 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1311 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1312 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1313 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1314 | |
| 1315 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1316 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1317 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1318 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1319 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1320 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1321 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1322 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1323 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1324 | |
| 1325 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1326 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1327 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1328 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1329 | } |
| 1330 | } |
| 1331 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1332 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1333 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1334 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1335 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1336 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1337 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1338 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1339 | request.method = "POST"; |
| 1340 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1341 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1342 | request.traffic_annotation = |
| 1343 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1344 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1345 | // Check the upload progress returned before initialization is correct. |
| 1346 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1347 | EXPECT_EQ(0u, progress.size()); |
| 1348 | EXPECT_EQ(0u, progress.position()); |
| 1349 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1350 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1351 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1352 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1353 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1354 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1355 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1356 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1357 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1358 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1359 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1360 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1361 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1362 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1363 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1364 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1365 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1366 | |
| 1367 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1368 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1369 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1370 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1371 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1372 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1373 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1374 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1375 | |
| 1376 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1377 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1378 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1379 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1380 | } |
| 1381 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1382 | // This test is almost the same as Ignores100 above, but the response contains |
| 1383 | // 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] | 1384 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1385 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1386 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1387 | request.method = "GET"; |
| 1388 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1389 | request.traffic_annotation = |
| 1390 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1391 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1392 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1393 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1394 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1395 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1396 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1397 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1398 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1399 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1400 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1401 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1402 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1403 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1404 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1405 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1406 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1407 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1408 | |
| 1409 | rv = callback.WaitForResult(); |
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 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1412 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1413 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1414 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1415 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1416 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1417 | |
| 1418 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1419 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1420 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1421 | EXPECT_EQ("hello world", response_data); |
| 1422 | } |
| 1423 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1424 | TEST_F(HttpNetworkTransactionTest, LoadTimingMeasuresTimeToFirstByteForHttp) { |
| 1425 | static const base::TimeDelta kDelayAfterFirstByte = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1426 | base::TimeDelta::FromMilliseconds(10); |
| 1427 | |
| 1428 | HttpRequestInfo request; |
| 1429 | request.method = "GET"; |
| 1430 | request.url = GURL("http://www.foo.com/"); |
| 1431 | request.traffic_annotation = |
| 1432 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1433 | |
| 1434 | std::vector<MockWrite> data_writes = { |
| 1435 | MockWrite(ASYNC, 0, |
| 1436 | "GET / HTTP/1.1\r\n" |
| 1437 | "Host: www.foo.com\r\n" |
| 1438 | "Connection: keep-alive\r\n\r\n"), |
| 1439 | }; |
| 1440 | |
| 1441 | std::vector<MockRead> data_reads = { |
| 1442 | // Write one byte of the status line, followed by a pause. |
| 1443 | MockRead(ASYNC, 1, "H"), |
| 1444 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1445 | MockRead(ASYNC, 3, "TTP/1.1 200 OK\r\n\r\n"), |
| 1446 | MockRead(ASYNC, 4, "hello world"), |
| 1447 | MockRead(SYNCHRONOUS, OK, 5), |
| 1448 | }; |
| 1449 | |
| 1450 | SequencedSocketData data(data_reads, data_writes); |
| 1451 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1452 | |
| 1453 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1454 | |
| 1455 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1456 | |
| 1457 | TestCompletionCallback callback; |
| 1458 | |
| 1459 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1460 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1461 | |
| 1462 | data.RunUntilPaused(); |
| 1463 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1464 | FastForwardBy(kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1465 | data.Resume(); |
| 1466 | |
| 1467 | rv = callback.WaitForResult(); |
| 1468 | EXPECT_THAT(rv, IsOk()); |
| 1469 | |
| 1470 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1471 | ASSERT_TRUE(response); |
| 1472 | |
| 1473 | EXPECT_TRUE(response->headers); |
| 1474 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1475 | |
| 1476 | LoadTimingInfo load_timing_info; |
| 1477 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1478 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1479 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1480 | // Ensure we didn't include the delay in the TTFB time. |
| 1481 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1482 | load_timing_info.connect_timing.connect_end); |
| 1483 | // Ensure that the mock clock advanced at all. |
| 1484 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1485 | kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1486 | |
| 1487 | std::string response_data; |
| 1488 | rv = ReadTransaction(&trans, &response_data); |
| 1489 | EXPECT_THAT(rv, IsOk()); |
| 1490 | EXPECT_EQ("hello world", response_data); |
| 1491 | } |
| 1492 | |
| 1493 | // Tests that the time-to-first-byte reported in a transaction's load timing |
| 1494 | // info uses the first response, even if 1XX/informational. |
| 1495 | void HttpNetworkTransactionTest::Check100ResponseTiming(bool use_spdy) { |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1496 | static const base::TimeDelta kDelayAfter100Response = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1497 | base::TimeDelta::FromMilliseconds(10); |
| 1498 | |
| 1499 | HttpRequestInfo request; |
| 1500 | request.method = "GET"; |
| 1501 | request.url = GURL("https://www.foo.com/"); |
| 1502 | request.traffic_annotation = |
| 1503 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1504 | |
| 1505 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 1506 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 1507 | |
| 1508 | std::vector<MockWrite> data_writes; |
| 1509 | std::vector<MockRead> data_reads; |
| 1510 | |
| 1511 | spdy::SpdySerializedFrame spdy_req( |
| 1512 | spdy_util_.ConstructSpdyGet(request.url.spec().c_str(), 1, LOWEST)); |
| 1513 | |
| 1514 | spdy::SpdyHeaderBlock spdy_resp1_headers; |
| 1515 | spdy_resp1_headers[spdy::kHttp2StatusHeader] = "100"; |
| 1516 | spdy::SpdySerializedFrame spdy_resp1( |
| 1517 | spdy_util_.ConstructSpdyReply(1, spdy_resp1_headers.Clone())); |
| 1518 | spdy::SpdySerializedFrame spdy_resp2( |
| 1519 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 1520 | spdy::SpdySerializedFrame spdy_data( |
| 1521 | spdy_util_.ConstructSpdyDataFrame(1, "hello world", true)); |
| 1522 | |
| 1523 | if (use_spdy) { |
| 1524 | ssl.next_proto = kProtoHTTP2; |
| 1525 | |
| 1526 | data_writes = {CreateMockWrite(spdy_req, 0)}; |
| 1527 | |
| 1528 | data_reads = { |
| 1529 | CreateMockRead(spdy_resp1, 1), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1530 | CreateMockRead(spdy_resp2, 3), CreateMockRead(spdy_data, 4), |
| 1531 | MockRead(SYNCHRONOUS, OK, 5), |
| 1532 | }; |
| 1533 | } else { |
| 1534 | data_writes = { |
| 1535 | MockWrite(ASYNC, 0, |
| 1536 | "GET / HTTP/1.1\r\n" |
| 1537 | "Host: www.foo.com\r\n" |
| 1538 | "Connection: keep-alive\r\n\r\n"), |
| 1539 | }; |
| 1540 | |
| 1541 | data_reads = { |
| 1542 | MockRead(ASYNC, 1, "HTTP/1.1 100 Continue\r\n\r\n"), |
| 1543 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1544 | |
| 1545 | MockRead(ASYNC, 3, "HTTP/1.1 200 OK\r\n\r\n"), |
| 1546 | MockRead(ASYNC, 4, "hello world"), |
| 1547 | MockRead(SYNCHRONOUS, OK, 5), |
| 1548 | }; |
| 1549 | } |
| 1550 | |
| 1551 | SequencedSocketData data(data_reads, data_writes); |
| 1552 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1553 | |
| 1554 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1555 | |
| 1556 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1557 | |
| 1558 | TestCompletionCallback callback; |
| 1559 | |
| 1560 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1561 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1562 | |
| 1563 | data.RunUntilPaused(); |
| 1564 | // We should now have parsed the 100 response and hit ERR_IO_PENDING. Insert |
| 1565 | // the delay before parsing the 200 response. |
| 1566 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1567 | FastForwardBy(kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1568 | data.Resume(); |
| 1569 | |
| 1570 | rv = callback.WaitForResult(); |
| 1571 | EXPECT_THAT(rv, IsOk()); |
| 1572 | |
| 1573 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1574 | ASSERT_TRUE(response); |
| 1575 | |
| 1576 | LoadTimingInfo load_timing_info; |
| 1577 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1578 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1579 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1580 | // Ensure we didn't include the delay in the TTFB time. |
| 1581 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1582 | load_timing_info.connect_timing.connect_end); |
| 1583 | // Ensure that the mock clock advanced at all. |
| 1584 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1585 | kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1586 | |
| 1587 | std::string response_data; |
| 1588 | rv = ReadTransaction(&trans, &response_data); |
| 1589 | EXPECT_THAT(rv, IsOk()); |
| 1590 | EXPECT_EQ("hello world", response_data); |
| 1591 | } |
| 1592 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1593 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForHttp) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1594 | Check100ResponseTiming(false /* use_spdy */); |
| 1595 | } |
| 1596 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1597 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForSpdy) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1598 | Check100ResponseTiming(true /* use_spdy */); |
| 1599 | } |
| 1600 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1601 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1602 | HttpRequestInfo request; |
| 1603 | request.method = "POST"; |
| 1604 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1605 | request.traffic_annotation = |
| 1606 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1607 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1608 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1609 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1610 | |
| 1611 | MockRead data_reads[] = { |
| 1612 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1613 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1614 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1615 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1616 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1617 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1618 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1619 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1620 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1621 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1622 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1623 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1624 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1625 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1626 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1627 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1628 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1629 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1630 | } |
| 1631 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1632 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1633 | HttpRequestInfo request; |
| 1634 | request.method = "POST"; |
| 1635 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1636 | request.traffic_annotation = |
| 1637 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1638 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1639 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1640 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1641 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1642 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1643 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1644 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1645 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1646 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1647 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1648 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1649 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1650 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1651 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1652 | |
| 1653 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1654 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1655 | } |
| 1656 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1657 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1658 | const MockWrite* write_failure, |
| 1659 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1660 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1661 | request.method = "GET"; |
| 1662 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1663 | request.traffic_annotation = |
| 1664 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1665 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1666 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1667 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1668 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1669 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1670 | // Written data for successfully sending both requests. |
| 1671 | MockWrite data1_writes[] = { |
| 1672 | MockWrite("GET / HTTP/1.1\r\n" |
| 1673 | "Host: www.foo.com\r\n" |
| 1674 | "Connection: keep-alive\r\n\r\n"), |
| 1675 | MockWrite("GET / HTTP/1.1\r\n" |
| 1676 | "Host: www.foo.com\r\n" |
| 1677 | "Connection: keep-alive\r\n\r\n") |
| 1678 | }; |
| 1679 | |
| 1680 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1681 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1682 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1683 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1684 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1685 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1686 | |
| 1687 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1688 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1689 | data1_writes[1] = *write_failure; |
| 1690 | } else { |
| 1691 | ASSERT_TRUE(read_failure); |
| 1692 | data1_reads[2] = *read_failure; |
| 1693 | } |
| 1694 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1695 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1696 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1697 | |
| 1698 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1699 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1700 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1701 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1702 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1703 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1704 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1705 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1706 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1707 | "hello", "world" |
| 1708 | }; |
| 1709 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1710 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1711 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1712 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1713 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1714 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1715 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1716 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1717 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1718 | |
| 1719 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1720 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1721 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1722 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1723 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1724 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1725 | if (i == 0) { |
| 1726 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1727 | } else { |
| 1728 | // The second request should be using a new socket. |
| 1729 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1730 | } |
| 1731 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1732 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1733 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1734 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1735 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1736 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1737 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1738 | |
| 1739 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1740 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1741 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1742 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1743 | } |
| 1744 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1745 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1746 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1747 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1748 | const MockRead* read_failure, |
| 1749 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1750 | HttpRequestInfo request; |
| 1751 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1752 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1753 | request.traffic_annotation = |
| 1754 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1755 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1756 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1757 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1758 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1759 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1760 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1761 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1762 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1763 | ssl1.next_proto = kProtoHTTP2; |
| 1764 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1765 | } |
| 1766 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1767 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1768 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1769 | // SPDY versions of the request and response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1770 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1771 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1772 | spdy::SpdySerializedFrame spdy_response( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1773 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1774 | spdy::SpdySerializedFrame spdy_data( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 1775 | spdy_util_.ConstructSpdyDataFrame(1, "hello", true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1776 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1777 | // HTTP/1.1 versions of the request and response. |
| 1778 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1779 | "Host: www.foo.com\r\n" |
| 1780 | "Connection: keep-alive\r\n\r\n"; |
| 1781 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1782 | const char kHttpData[] = "hello"; |
| 1783 | |
| 1784 | std::vector<MockRead> data1_reads; |
| 1785 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1786 | if (write_failure) { |
| 1787 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1788 | data1_writes.push_back(*write_failure); |
| 1789 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1790 | } else { |
| 1791 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1792 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1793 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1794 | } else { |
| 1795 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1796 | } |
| 1797 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1798 | } |
| 1799 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1800 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1801 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1802 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1803 | std::vector<MockRead> data2_reads; |
| 1804 | std::vector<MockWrite> data2_writes; |
| 1805 | |
| 1806 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1807 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1808 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1809 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1810 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1811 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1812 | } else { |
| 1813 | data2_writes.push_back( |
| 1814 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1815 | |
| 1816 | data2_reads.push_back( |
| 1817 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1818 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1819 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1820 | } |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1821 | SequencedSocketData data2(data2_reads, data2_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1822 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1823 | |
| 1824 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1825 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1826 | // Wait for the preconnect to complete. |
| 1827 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1828 | base::RunLoop().RunUntilIdle(); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 1829 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1830 | |
| 1831 | // Make the request. |
| 1832 | TestCompletionCallback callback; |
| 1833 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1834 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1835 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1836 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1837 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1838 | |
| 1839 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1840 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1841 | |
| 1842 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1843 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1844 | TestLoadTimingNotReused( |
| 1845 | load_timing_info, |
| 1846 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1847 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1848 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1849 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1850 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1851 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1852 | if (response->was_fetched_via_spdy) { |
| 1853 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1854 | } else { |
| 1855 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1856 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1857 | |
| 1858 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1859 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1860 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1861 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1862 | } |
| 1863 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1864 | // Test that we do not retry indefinitely when a server sends an error like |
| 1865 | // ERR_SPDY_PING_FAILED, ERR_SPDY_SERVER_REFUSED_STREAM, |
| 1866 | // ERR_QUIC_HANDSHAKE_FAILED or ERR_QUIC_PROTOCOL_ERROR. |
| 1867 | TEST_F(HttpNetworkTransactionTest, FiniteRetriesOnIOError) { |
| 1868 | HttpRequestInfo request; |
| 1869 | request.method = "GET"; |
| 1870 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1871 | request.traffic_annotation = |
| 1872 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1873 | |
| 1874 | // Check whether we give up after the third try. |
| 1875 | |
| 1876 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1877 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1878 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1879 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1880 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1881 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1882 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1883 | |
| 1884 | // Three go away responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1885 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1886 | StaticSocketDataProvider data2(data_read1, data_write); |
| 1887 | StaticSocketDataProvider data3(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1888 | |
| 1889 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1890 | AddSSLSocketData(); |
| 1891 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1892 | AddSSLSocketData(); |
| 1893 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1894 | AddSSLSocketData(); |
| 1895 | |
| 1896 | TestCompletionCallback callback; |
| 1897 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1898 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1899 | |
| 1900 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1901 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1902 | |
| 1903 | rv = callback.WaitForResult(); |
| 1904 | EXPECT_THAT(rv, IsError(ERR_SPDY_SERVER_REFUSED_STREAM)); |
| 1905 | } |
| 1906 | |
| 1907 | TEST_F(HttpNetworkTransactionTest, RetryTwiceOnIOError) { |
| 1908 | HttpRequestInfo request; |
| 1909 | request.method = "GET"; |
| 1910 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1911 | request.traffic_annotation = |
| 1912 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1913 | |
| 1914 | // Check whether we try atleast thrice before giving up. |
| 1915 | |
| 1916 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1917 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1918 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1919 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1920 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1921 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1922 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1923 | |
| 1924 | // Construct a non error HTTP2 response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1925 | spdy::SpdySerializedFrame spdy_response_no_error( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1926 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1927 | spdy::SpdySerializedFrame spdy_data( |
| 1928 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1929 | MockRead data_read2[] = {CreateMockRead(spdy_response_no_error, 1), |
| 1930 | CreateMockRead(spdy_data, 2)}; |
| 1931 | |
| 1932 | // Two error responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1933 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1934 | StaticSocketDataProvider data2(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1935 | // Followed by a success response. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1936 | SequencedSocketData data3(data_read2, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1937 | |
| 1938 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1939 | AddSSLSocketData(); |
| 1940 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1941 | AddSSLSocketData(); |
| 1942 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1943 | AddSSLSocketData(); |
| 1944 | |
| 1945 | TestCompletionCallback callback; |
| 1946 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1947 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1948 | |
| 1949 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1950 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1951 | |
| 1952 | rv = callback.WaitForResult(); |
| 1953 | EXPECT_THAT(rv, IsOk()); |
| 1954 | } |
| 1955 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1956 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1957 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1958 | KeepAliveConnectionResendRequestTest(&write_failure, nullptr); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1959 | } |
| 1960 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1961 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1962 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1963 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1964 | } |
| 1965 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1966 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1967 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1968 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1969 | } |
| 1970 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1971 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1972 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1973 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1974 | MockRead read_failure(SYNCHRONOUS, |
| 1975 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1976 | "Connection: Keep-Alive\r\n" |
| 1977 | "Content-Length: 6\r\n\r\n" |
| 1978 | "Pickle"); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1979 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1980 | } |
| 1981 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1982 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1983 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1984 | PreconnectErrorResendRequestTest(&write_failure, nullptr, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1985 | } |
| 1986 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1987 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1988 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1989 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1990 | } |
| 1991 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1992 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1993 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1994 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1995 | } |
| 1996 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1997 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1998 | MockRead read_failure(ASYNC, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1999 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2000 | } |
| 2001 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2002 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 2003 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2004 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2005 | MockRead read_failure(SYNCHRONOUS, |
| 2006 | "HTTP/1.1 408 Request Timeout\r\n" |
| 2007 | "Connection: Keep-Alive\r\n" |
| 2008 | "Content-Length: 6\r\n\r\n" |
| 2009 | "Pickle"); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2010 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
| 2011 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2012 | } |
| 2013 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2014 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2015 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2016 | PreconnectErrorResendRequestTest(&write_failure, nullptr, 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, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2020 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2021 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2022 | } |
| 2023 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2024 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2025 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2026 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2027 | } |
| 2028 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2029 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2030 | MockRead read_failure(ASYNC, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2031 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2032 | } |
| 2033 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2034 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2035 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2036 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2037 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2038 | request.traffic_annotation = |
| 2039 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2040 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2041 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2042 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2043 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2044 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2045 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2046 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2047 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2048 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2049 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2050 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2051 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2052 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2053 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2054 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2055 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2056 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2057 | |
| 2058 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2059 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2060 | |
| 2061 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2062 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2063 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | // What do various browsers do when the server closes a non-keepalive |
| 2067 | // connection without sending any response header or body? |
| 2068 | // |
| 2069 | // IE7: error page |
| 2070 | // Safari 3.1.2 (Windows): error page |
| 2071 | // Firefox 3.0.1: blank page |
| 2072 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2073 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 2074 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2075 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2076 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2077 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2078 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2079 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2080 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2081 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2082 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2083 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2084 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 2085 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2086 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 2087 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 2088 | // destructor in such situations. |
| 2089 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2090 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2091 | HttpRequestInfo request; |
| 2092 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2093 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2094 | request.traffic_annotation = |
| 2095 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2096 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2097 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2098 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2099 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2100 | |
| 2101 | MockRead data_reads[] = { |
| 2102 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2103 | MockRead("Connection: keep-alive\r\n"), |
| 2104 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2105 | MockRead("hello"), |
| 2106 | MockRead(SYNCHRONOUS, 0), |
| 2107 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2108 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2109 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2110 | |
| 2111 | TestCompletionCallback callback; |
| 2112 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2113 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2114 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2115 | |
| 2116 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2117 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2118 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2119 | scoped_refptr<IOBufferWithSize> io_buf = |
| 2120 | base::MakeRefCounted<IOBufferWithSize>(100); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2121 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2122 | if (rv == ERR_IO_PENDING) |
| 2123 | rv = callback.WaitForResult(); |
| 2124 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2125 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2126 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2127 | |
| 2128 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2129 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2130 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2131 | } |
| 2132 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2133 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2134 | HttpRequestInfo request; |
| 2135 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2136 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2137 | request.traffic_annotation = |
| 2138 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2139 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2140 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2141 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2142 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2143 | |
| 2144 | MockRead data_reads[] = { |
| 2145 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2146 | MockRead("Connection: keep-alive\r\n"), |
| 2147 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2148 | MockRead(SYNCHRONOUS, 0), |
| 2149 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2150 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2151 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2152 | |
| 2153 | TestCompletionCallback callback; |
| 2154 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2155 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2156 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2157 | |
| 2158 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2159 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2160 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2161 | scoped_refptr<IOBufferWithSize> io_buf( |
| 2162 | base::MakeRefCounted<IOBufferWithSize>(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2163 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2164 | if (rv == ERR_IO_PENDING) |
| 2165 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2166 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2167 | |
| 2168 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2169 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2170 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2171 | } |
| 2172 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2173 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 2174 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2175 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2176 | HttpRequestInfo request; |
| 2177 | request.method = "GET"; |
| 2178 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2179 | request.traffic_annotation = |
| 2180 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2181 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2182 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2183 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2184 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2185 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2186 | const char* request_data = |
| 2187 | "GET / HTTP/1.1\r\n" |
| 2188 | "Host: www.foo.com\r\n" |
| 2189 | "Connection: keep-alive\r\n\r\n"; |
| 2190 | MockWrite data_writes[] = { |
| 2191 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 2192 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 2193 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 2194 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 2195 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 2196 | }; |
| 2197 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2198 | // Note that because all these reads happen in the same |
| 2199 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 2200 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2201 | MockRead data_reads[] = { |
| 2202 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 2203 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 2204 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 2205 | MockRead(ASYNC, 7, |
| 2206 | "HTTP/1.1 302 Found\r\n" |
| 2207 | "Content-Length: 0\r\n\r\n"), |
| 2208 | MockRead(ASYNC, 9, |
| 2209 | "HTTP/1.1 302 Found\r\n" |
| 2210 | "Content-Length: 5\r\n\r\n" |
| 2211 | "hello"), |
| 2212 | MockRead(ASYNC, 11, |
| 2213 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2214 | "Content-Length: 0\r\n\r\n"), |
| 2215 | MockRead(ASYNC, 13, |
| 2216 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2217 | "Content-Length: 5\r\n\r\n" |
| 2218 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2219 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2220 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 2221 | // the set_busy_before_sync_reads(true) call, while the |
| 2222 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 2223 | // reuseable. See http://crbug.com/544255. |
| 2224 | MockRead(ASYNC, 15, |
| 2225 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2226 | "Content-Length: 5\r\n\r\n"), |
| 2227 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2228 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2229 | MockRead(ASYNC, 18, |
| 2230 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2231 | "Content-Length: 5\r\n\r\n" |
| 2232 | "he"), |
| 2233 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 2234 | |
| 2235 | // The body of the final request is actually read. |
| 2236 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 2237 | MockRead(ASYNC, 22, "hello"), |
| 2238 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2239 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2240 | data.set_busy_before_sync_reads(true); |
| 2241 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2242 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2243 | const int kNumUnreadBodies = base::size(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2244 | std::string response_lines[kNumUnreadBodies]; |
| 2245 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 2246 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2247 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2248 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2249 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2250 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2251 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2252 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2253 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2254 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2255 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2256 | LoadTimingInfo load_timing_info; |
| 2257 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2258 | if (i == 0) { |
| 2259 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2260 | first_socket_log_id = load_timing_info.socket_log_id; |
| 2261 | } else { |
| 2262 | TestLoadTimingReused(load_timing_info); |
| 2263 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 2264 | } |
| 2265 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2266 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2267 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2268 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2269 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2270 | response_lines[i] = response->headers->GetStatusLine(); |
| 2271 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2272 | // Delete the transaction without reading the response bodies. Then spin |
| 2273 | // the message loop, so the response bodies are drained. |
| 2274 | trans.reset(); |
| 2275 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2276 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2277 | |
| 2278 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2279 | "HTTP/1.1 204 No Content", |
| 2280 | "HTTP/1.1 205 Reset Content", |
| 2281 | "HTTP/1.1 304 Not Modified", |
| 2282 | "HTTP/1.1 302 Found", |
| 2283 | "HTTP/1.1 302 Found", |
| 2284 | "HTTP/1.1 301 Moved Permanently", |
| 2285 | "HTTP/1.1 301 Moved Permanently", |
| 2286 | "HTTP/1.1 200 Hunky-Dory", |
| 2287 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2288 | }; |
| 2289 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2290 | static_assert(kNumUnreadBodies == base::size(kStatusLines), |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2291 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2292 | |
| 2293 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2294 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2295 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2296 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2297 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2298 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2299 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2300 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2301 | ASSERT_TRUE(response); |
| 2302 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2303 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2304 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2305 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2306 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2307 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2308 | } |
| 2309 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2310 | // Sockets that receive extra data after a response is complete should not be |
| 2311 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2312 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2313 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2314 | MockWrite data_writes1[] = { |
| 2315 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2316 | "Host: www.borked.com\r\n" |
| 2317 | "Connection: keep-alive\r\n\r\n"), |
| 2318 | }; |
| 2319 | |
| 2320 | MockRead data_reads1[] = { |
| 2321 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2322 | "Connection: keep-alive\r\n" |
| 2323 | "Content-Length: 22\r\n\r\n" |
| 2324 | "This server is borked."), |
| 2325 | }; |
| 2326 | |
| 2327 | MockWrite data_writes2[] = { |
| 2328 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2329 | "Host: www.borked.com\r\n" |
| 2330 | "Connection: keep-alive\r\n\r\n"), |
| 2331 | }; |
| 2332 | |
| 2333 | MockRead data_reads2[] = { |
| 2334 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2335 | "Content-Length: 3\r\n\r\n" |
| 2336 | "foo"), |
| 2337 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2338 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2339 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2340 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2341 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2342 | |
| 2343 | TestCompletionCallback callback; |
| 2344 | HttpRequestInfo request1; |
| 2345 | request1.method = "HEAD"; |
| 2346 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2347 | request1.traffic_annotation = |
| 2348 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2349 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2350 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2351 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2352 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2353 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2354 | |
| 2355 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2356 | ASSERT_TRUE(response1); |
| 2357 | ASSERT_TRUE(response1->headers); |
| 2358 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2359 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2360 | |
| 2361 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2362 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2363 | EXPECT_EQ("", response_data1); |
| 2364 | // Deleting the transaction attempts to release the socket back into the |
| 2365 | // socket pool. |
| 2366 | trans1.reset(); |
| 2367 | |
| 2368 | HttpRequestInfo request2; |
| 2369 | request2.method = "GET"; |
| 2370 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2371 | request2.traffic_annotation = |
| 2372 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2373 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2374 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2375 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2376 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2377 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2378 | |
| 2379 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2380 | ASSERT_TRUE(response2); |
| 2381 | ASSERT_TRUE(response2->headers); |
| 2382 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2383 | |
| 2384 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2385 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2386 | EXPECT_EQ("foo", response_data2); |
| 2387 | } |
| 2388 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2389 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2390 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2391 | MockWrite data_writes1[] = { |
| 2392 | MockWrite("GET / HTTP/1.1\r\n" |
| 2393 | "Host: www.borked.com\r\n" |
| 2394 | "Connection: keep-alive\r\n\r\n"), |
| 2395 | }; |
| 2396 | |
| 2397 | MockRead data_reads1[] = { |
| 2398 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2399 | "Connection: keep-alive\r\n" |
| 2400 | "Content-Length: 22\r\n\r\n" |
| 2401 | "This server is borked." |
| 2402 | "Bonus data!"), |
| 2403 | }; |
| 2404 | |
| 2405 | MockWrite data_writes2[] = { |
| 2406 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2407 | "Host: www.borked.com\r\n" |
| 2408 | "Connection: keep-alive\r\n\r\n"), |
| 2409 | }; |
| 2410 | |
| 2411 | MockRead data_reads2[] = { |
| 2412 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2413 | "Content-Length: 3\r\n\r\n" |
| 2414 | "foo"), |
| 2415 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2416 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2417 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2418 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2419 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2420 | |
| 2421 | TestCompletionCallback callback; |
| 2422 | HttpRequestInfo request1; |
| 2423 | request1.method = "GET"; |
| 2424 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2425 | request1.traffic_annotation = |
| 2426 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2427 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2428 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2429 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2430 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2431 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2432 | |
| 2433 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2434 | ASSERT_TRUE(response1); |
| 2435 | ASSERT_TRUE(response1->headers); |
| 2436 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2437 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2438 | |
| 2439 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2440 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2441 | EXPECT_EQ("This server is borked.", response_data1); |
| 2442 | // Deleting the transaction attempts to release the socket back into the |
| 2443 | // socket pool. |
| 2444 | trans1.reset(); |
| 2445 | |
| 2446 | HttpRequestInfo request2; |
| 2447 | request2.method = "GET"; |
| 2448 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2449 | request2.traffic_annotation = |
| 2450 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2451 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2452 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2453 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2454 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2455 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2456 | |
| 2457 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2458 | ASSERT_TRUE(response2); |
| 2459 | ASSERT_TRUE(response2->headers); |
| 2460 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2461 | |
| 2462 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2463 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2464 | EXPECT_EQ("foo", response_data2); |
| 2465 | } |
| 2466 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2467 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2468 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2469 | MockWrite data_writes1[] = { |
| 2470 | MockWrite("GET / HTTP/1.1\r\n" |
| 2471 | "Host: www.borked.com\r\n" |
| 2472 | "Connection: keep-alive\r\n\r\n"), |
| 2473 | }; |
| 2474 | |
| 2475 | MockRead data_reads1[] = { |
| 2476 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2477 | "Connection: keep-alive\r\n" |
| 2478 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2479 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2480 | MockRead("0\r\n\r\nBonus data!"), |
| 2481 | }; |
| 2482 | |
| 2483 | MockWrite data_writes2[] = { |
| 2484 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2485 | "Host: www.borked.com\r\n" |
| 2486 | "Connection: keep-alive\r\n\r\n"), |
| 2487 | }; |
| 2488 | |
| 2489 | MockRead data_reads2[] = { |
| 2490 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2491 | "Content-Length: 3\r\n\r\n" |
| 2492 | "foo"), |
| 2493 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2494 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2495 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2496 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2497 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2498 | |
| 2499 | TestCompletionCallback callback; |
| 2500 | HttpRequestInfo request1; |
| 2501 | request1.method = "GET"; |
| 2502 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2503 | request1.traffic_annotation = |
| 2504 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2505 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2506 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2507 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2508 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2509 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2510 | |
| 2511 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2512 | ASSERT_TRUE(response1); |
| 2513 | ASSERT_TRUE(response1->headers); |
| 2514 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2515 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2516 | |
| 2517 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2518 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2519 | EXPECT_EQ("This server is borked.", response_data1); |
| 2520 | // Deleting the transaction attempts to release the socket back into the |
| 2521 | // socket pool. |
| 2522 | trans1.reset(); |
| 2523 | |
| 2524 | HttpRequestInfo request2; |
| 2525 | request2.method = "GET"; |
| 2526 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2527 | request2.traffic_annotation = |
| 2528 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2529 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2530 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2531 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2532 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2533 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2534 | |
| 2535 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2536 | ASSERT_TRUE(response2); |
| 2537 | ASSERT_TRUE(response2->headers); |
| 2538 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2539 | |
| 2540 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2541 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2542 | EXPECT_EQ("foo", response_data2); |
| 2543 | } |
| 2544 | |
| 2545 | // This is a little different from the others - it tests the case that the |
| 2546 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2547 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2548 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2549 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2550 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2551 | MockWrite data_writes1[] = { |
| 2552 | MockWrite("GET / HTTP/1.1\r\n" |
| 2553 | "Host: www.borked.com\r\n" |
| 2554 | "Connection: keep-alive\r\n\r\n"), |
| 2555 | }; |
| 2556 | |
| 2557 | MockRead data_reads1[] = { |
| 2558 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2559 | "Connection: keep-alive\r\n" |
| 2560 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2561 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2562 | MockRead("0\r\n\r\nBonus data!"), |
| 2563 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2564 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2565 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2566 | |
| 2567 | TestCompletionCallback callback; |
| 2568 | HttpRequestInfo request1; |
| 2569 | request1.method = "GET"; |
| 2570 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2571 | request1.traffic_annotation = |
| 2572 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2573 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2574 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2575 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2576 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2577 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2578 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2579 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2580 | ASSERT_TRUE(response1); |
| 2581 | ASSERT_TRUE(response1->headers); |
| 2582 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2583 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2584 | |
| 2585 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2586 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2587 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2588 | |
| 2589 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2590 | // socket can't be reused, rather than returning it to the socket pool. |
| 2591 | base::RunLoop().RunUntilIdle(); |
| 2592 | |
| 2593 | // There should be no idle sockets in the pool. |
| 2594 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2595 | } |
| 2596 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2597 | // Test the request-challenge-retry sequence for basic auth. |
| 2598 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2599 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2600 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2601 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2602 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2603 | request.traffic_annotation = |
| 2604 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2605 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2606 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2607 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2608 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2609 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2610 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2611 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2612 | MockWrite( |
| 2613 | "GET / HTTP/1.1\r\n" |
| 2614 | "Host: www.example.org\r\n" |
| 2615 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2616 | }; |
| 2617 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2618 | MockRead data_reads1[] = { |
| 2619 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2620 | // Give a couple authenticate options (only the middle one is actually |
| 2621 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2622 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2623 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2624 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2625 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2626 | // Large content-length -- won't matter, as connection will be reset. |
| 2627 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2628 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2629 | }; |
| 2630 | |
| 2631 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2632 | // be issuing -- the final header line contains the credentials. |
| 2633 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2634 | MockWrite( |
| 2635 | "GET / HTTP/1.1\r\n" |
| 2636 | "Host: www.example.org\r\n" |
| 2637 | "Connection: keep-alive\r\n" |
| 2638 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2639 | }; |
| 2640 | |
| 2641 | // Lastly, the server responds with the actual content. |
| 2642 | MockRead data_reads2[] = { |
| 2643 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2644 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2645 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2646 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2647 | }; |
| 2648 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2649 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2650 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2651 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2652 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2653 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2654 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2655 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2656 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2657 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2658 | |
| 2659 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2660 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2661 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2662 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2663 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2664 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2665 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2666 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2667 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2668 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2669 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2670 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2671 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2672 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2673 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2674 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2675 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2676 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2677 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2678 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2679 | |
| 2680 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2681 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2682 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2683 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2684 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2685 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2686 | // The load timing after restart should have a new socket ID, and times after |
| 2687 | // those of the first load timing. |
| 2688 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2689 | load_timing_info2.connect_timing.connect_start); |
| 2690 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2691 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2692 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2693 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2694 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2695 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2696 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2697 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2698 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2699 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2700 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2701 | } |
| 2702 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2703 | // Test the request-challenge-retry sequence for basic auth. |
| 2704 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2705 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2706 | HttpRequestInfo request; |
| 2707 | request.method = "GET"; |
| 2708 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2709 | request.traffic_annotation = |
| 2710 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2711 | |
| 2712 | TestNetLog log; |
| 2713 | MockHostResolver* resolver = new MockHostResolver(); |
| 2714 | session_deps_.net_log = &log; |
| 2715 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2716 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2717 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2718 | |
| 2719 | resolver->rules()->ClearRules(); |
| 2720 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2721 | |
| 2722 | MockWrite data_writes1[] = { |
| 2723 | MockWrite("GET / HTTP/1.1\r\n" |
| 2724 | "Host: www.example.org\r\n" |
| 2725 | "Connection: keep-alive\r\n\r\n"), |
| 2726 | }; |
| 2727 | |
| 2728 | MockRead data_reads1[] = { |
| 2729 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2730 | // Give a couple authenticate options (only the middle one is actually |
| 2731 | // supported). |
| 2732 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2733 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2734 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2735 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2736 | // Large content-length -- won't matter, as connection will be reset. |
| 2737 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2738 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2739 | }; |
| 2740 | |
| 2741 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2742 | // be issuing -- the final header line contains the credentials. |
| 2743 | MockWrite data_writes2[] = { |
| 2744 | MockWrite("GET / HTTP/1.1\r\n" |
| 2745 | "Host: www.example.org\r\n" |
| 2746 | "Connection: keep-alive\r\n" |
| 2747 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2748 | }; |
| 2749 | |
| 2750 | // Lastly, the server responds with the actual content. |
| 2751 | MockRead data_reads2[] = { |
| 2752 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2753 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2754 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2755 | }; |
| 2756 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2757 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2758 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2759 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2760 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2761 | |
| 2762 | TestCompletionCallback callback1; |
| 2763 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2764 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2765 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2766 | |
| 2767 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2768 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2769 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2770 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2771 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2772 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2773 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2774 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2775 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2776 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2777 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2778 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2779 | |
| 2780 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2781 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2782 | ASSERT_FALSE(endpoint.address().empty()); |
| 2783 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2784 | |
| 2785 | resolver->rules()->ClearRules(); |
| 2786 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2787 | |
| 2788 | TestCompletionCallback callback2; |
| 2789 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2790 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2791 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2792 | |
| 2793 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2794 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2795 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2796 | // The load timing after restart should have a new socket ID, and times after |
| 2797 | // those of the first load timing. |
| 2798 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2799 | load_timing_info2.connect_timing.connect_start); |
| 2800 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2801 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2802 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2803 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2804 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2805 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2806 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2807 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2808 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2809 | EXPECT_FALSE(response->auth_challenge.has_value()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2810 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2811 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2812 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2813 | ASSERT_FALSE(endpoint.address().empty()); |
| 2814 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2815 | } |
| 2816 | |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2817 | // Test that, if the server requests auth indefinitely, HttpNetworkTransaction |
| 2818 | // will eventually give up. |
| 2819 | TEST_F(HttpNetworkTransactionTest, BasicAuthForever) { |
| 2820 | HttpRequestInfo request; |
| 2821 | request.method = "GET"; |
| 2822 | request.url = GURL("http://www.example.org/"); |
| 2823 | request.traffic_annotation = |
| 2824 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2825 | |
| 2826 | TestNetLog log; |
| 2827 | session_deps_.net_log = &log; |
| 2828 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2829 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 2830 | |
| 2831 | MockWrite data_writes[] = { |
| 2832 | MockWrite("GET / HTTP/1.1\r\n" |
| 2833 | "Host: www.example.org\r\n" |
| 2834 | "Connection: keep-alive\r\n\r\n"), |
| 2835 | }; |
| 2836 | |
| 2837 | MockRead data_reads[] = { |
| 2838 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2839 | // Give a couple authenticate options (only the middle one is actually |
| 2840 | // supported). |
| 2841 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2842 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2843 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2844 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2845 | // Large content-length -- won't matter, as connection will be reset. |
| 2846 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2847 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2848 | }; |
| 2849 | |
| 2850 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2851 | // be issuing -- the final header line contains the credentials. |
| 2852 | MockWrite data_writes_restart[] = { |
| 2853 | MockWrite("GET / HTTP/1.1\r\n" |
| 2854 | "Host: www.example.org\r\n" |
| 2855 | "Connection: keep-alive\r\n" |
| 2856 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2857 | }; |
| 2858 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2859 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2860 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2861 | |
| 2862 | TestCompletionCallback callback; |
| 2863 | int rv = callback.GetResult( |
| 2864 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 2865 | |
| 2866 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_restarts; |
| 2867 | for (int i = 0; i < 32; i++) { |
| 2868 | // Check the previous response was a 401. |
| 2869 | EXPECT_THAT(rv, IsOk()); |
| 2870 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 2871 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2872 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2873 | |
| 2874 | data_restarts.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2875 | data_reads, data_writes_restart)); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2876 | session_deps_.socket_factory->AddSocketDataProvider( |
| 2877 | data_restarts.back().get()); |
| 2878 | rv = callback.GetResult(trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2879 | callback.callback())); |
| 2880 | } |
| 2881 | |
| 2882 | // After too many tries, the transaction should have given up. |
| 2883 | EXPECT_THAT(rv, IsError(ERR_TOO_MANY_RETRIES)); |
| 2884 | } |
| 2885 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2886 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2887 | HttpRequestInfo request; |
| 2888 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2889 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2890 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2891 | request.traffic_annotation = |
| 2892 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2893 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2894 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2895 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2896 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2897 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2898 | MockWrite( |
| 2899 | "GET / HTTP/1.1\r\n" |
| 2900 | "Host: www.example.org\r\n" |
| 2901 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2902 | }; |
| 2903 | |
| 2904 | MockRead data_reads[] = { |
| 2905 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2906 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2907 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2908 | // Large content-length -- won't matter, as connection will be reset. |
| 2909 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2910 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2911 | }; |
| 2912 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2913 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2914 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2915 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2916 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2917 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2918 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2919 | |
| 2920 | rv = callback.WaitForResult(); |
| 2921 | EXPECT_EQ(0, rv); |
| 2922 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2923 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2924 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2925 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2926 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2927 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2928 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2929 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2930 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2931 | } |
| 2932 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2933 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2934 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2935 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2936 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2937 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2938 | // reused. See http://crbug.com/544255. |
| 2939 | for (int i = 0; i < 2; ++i) { |
| 2940 | HttpRequestInfo request; |
| 2941 | request.method = "GET"; |
| 2942 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2943 | request.traffic_annotation = |
| 2944 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2945 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2946 | TestNetLog log; |
| 2947 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2948 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2949 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2950 | MockWrite data_writes[] = { |
| 2951 | MockWrite(ASYNC, 0, |
| 2952 | "GET / HTTP/1.1\r\n" |
| 2953 | "Host: www.example.org\r\n" |
| 2954 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2955 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2956 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2957 | // be issuing -- the final header line contains the credentials. |
| 2958 | MockWrite(ASYNC, 6, |
| 2959 | "GET / HTTP/1.1\r\n" |
| 2960 | "Host: www.example.org\r\n" |
| 2961 | "Connection: keep-alive\r\n" |
| 2962 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2963 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2964 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2965 | MockRead data_reads[] = { |
| 2966 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2967 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2968 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2969 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2970 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2971 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2972 | // Lastly, the server responds with the actual content. |
| 2973 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2974 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2975 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2976 | MockRead(ASYNC, 10, "Hello"), |
| 2977 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2978 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2979 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2980 | data.set_busy_before_sync_reads(true); |
| 2981 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2982 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2983 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2984 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2985 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2986 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2987 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2988 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2989 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2990 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2991 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2992 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2993 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2994 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2995 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2996 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2997 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2998 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2999 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 3000 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3001 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3002 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3003 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3004 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3005 | TestLoadTimingReused(load_timing_info2); |
| 3006 | // The load timing after restart should have the same socket ID, and times |
| 3007 | // those of the first load timing. |
| 3008 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 3009 | load_timing_info2.send_start); |
| 3010 | 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] | 3011 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3012 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3013 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3014 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3015 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3016 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3017 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3018 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3019 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3020 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3021 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3022 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3023 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3024 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3025 | } |
| 3026 | |
| 3027 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3028 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3029 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3030 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3031 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3032 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3033 | request.traffic_annotation = |
| 3034 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3035 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3036 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3037 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3038 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3039 | MockWrite("GET / HTTP/1.1\r\n" |
| 3040 | "Host: www.example.org\r\n" |
| 3041 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3042 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3043 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3044 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3045 | MockWrite("GET / HTTP/1.1\r\n" |
| 3046 | "Host: www.example.org\r\n" |
| 3047 | "Connection: keep-alive\r\n" |
| 3048 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3049 | }; |
| 3050 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3051 | MockRead data_reads1[] = { |
| 3052 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3053 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3054 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3055 | |
| 3056 | // Lastly, the server responds with the actual content. |
| 3057 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3058 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3059 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3060 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3061 | }; |
| 3062 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3063 | // An incorrect reconnect would cause this to be read. |
| 3064 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3065 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3066 | }; |
| 3067 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3068 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3069 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3070 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3071 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3072 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3073 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3074 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3075 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3076 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3077 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3078 | |
| 3079 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3080 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3081 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3082 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3083 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3084 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3085 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3086 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3087 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3088 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3089 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3090 | |
| 3091 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3092 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3093 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3094 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3095 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3096 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3097 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3098 | } |
| 3099 | |
| 3100 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3101 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3102 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3103 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3104 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3105 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3106 | request.traffic_annotation = |
| 3107 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3108 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3109 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3110 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3111 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3112 | MockWrite("GET / HTTP/1.1\r\n" |
| 3113 | "Host: www.example.org\r\n" |
| 3114 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3115 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3116 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3117 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3118 | MockWrite("GET / HTTP/1.1\r\n" |
| 3119 | "Host: www.example.org\r\n" |
| 3120 | "Connection: keep-alive\r\n" |
| 3121 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3122 | }; |
| 3123 | |
| 3124 | // Respond with 5 kb of response body. |
| 3125 | std::string large_body_string("Unauthorized"); |
| 3126 | large_body_string.append(5 * 1024, ' '); |
| 3127 | large_body_string.append("\r\n"); |
| 3128 | |
| 3129 | MockRead data_reads1[] = { |
| 3130 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3131 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3132 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3133 | // 5134 = 12 + 5 * 1024 + 2 |
| 3134 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3135 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3136 | |
| 3137 | // Lastly, the server responds with the actual content. |
| 3138 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3139 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3140 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3141 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3142 | }; |
| 3143 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3144 | // An incorrect reconnect would cause this to be read. |
| 3145 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3146 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3147 | }; |
| 3148 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3149 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3150 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3151 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3152 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3153 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3154 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3155 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3156 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3157 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3158 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3159 | |
| 3160 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3161 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3162 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3163 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3164 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3165 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3166 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3167 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3168 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3169 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3170 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3171 | |
| 3172 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3173 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3174 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3175 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3176 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3177 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3178 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3179 | } |
| 3180 | |
| 3181 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3182 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3183 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3184 | HttpRequestInfo request; |
| 3185 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3186 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3187 | request.traffic_annotation = |
| 3188 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3189 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3190 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3191 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3192 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3193 | MockWrite( |
| 3194 | "GET / HTTP/1.1\r\n" |
| 3195 | "Host: www.example.org\r\n" |
| 3196 | "Connection: keep-alive\r\n\r\n"), |
| 3197 | // This simulates the seemingly successful write to a closed connection |
| 3198 | // if the bug is not fixed. |
| 3199 | MockWrite( |
| 3200 | "GET / HTTP/1.1\r\n" |
| 3201 | "Host: www.example.org\r\n" |
| 3202 | "Connection: keep-alive\r\n" |
| 3203 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3204 | }; |
| 3205 | |
| 3206 | MockRead data_reads1[] = { |
| 3207 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3208 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3209 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3210 | MockRead("Content-Length: 14\r\n\r\n"), |
| 3211 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3212 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3213 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3214 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3215 | }; |
| 3216 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3217 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3218 | // be issuing -- the final header line contains the credentials. |
| 3219 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3220 | MockWrite( |
| 3221 | "GET / HTTP/1.1\r\n" |
| 3222 | "Host: www.example.org\r\n" |
| 3223 | "Connection: keep-alive\r\n" |
| 3224 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3225 | }; |
| 3226 | |
| 3227 | // Lastly, the server responds with the actual content. |
| 3228 | MockRead data_reads2[] = { |
| 3229 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3230 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3231 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3232 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3233 | }; |
| 3234 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3235 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3236 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3237 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3238 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3239 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3240 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3241 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3242 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3243 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3244 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3245 | |
| 3246 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3247 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3248 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3249 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3250 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3251 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3252 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3253 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3254 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3255 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3256 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3257 | |
| 3258 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3259 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3260 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3261 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3262 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3263 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3264 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3265 | } |
| 3266 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3267 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3268 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3269 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3270 | HttpRequestInfo request; |
| 3271 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3272 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3273 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3274 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3275 | request.traffic_annotation = |
| 3276 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3277 | |
| 3278 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3279 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3280 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3281 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3282 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3283 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3284 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3285 | |
| 3286 | // Since we have proxy, should try to establish tunnel. |
| 3287 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3288 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3289 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3290 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3291 | }; |
| 3292 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3293 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3294 | // connection. |
| 3295 | MockRead data_reads1[] = { |
| 3296 | // No credentials. |
| 3297 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3298 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3299 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3300 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3301 | // Since the first connection couldn't be reused, need to establish another |
| 3302 | // once given credentials. |
| 3303 | MockWrite data_writes2[] = { |
| 3304 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3305 | // be issuing -- the final header line contains the credentials. |
| 3306 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3307 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3308 | "Proxy-Connection: keep-alive\r\n" |
| 3309 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3310 | |
| 3311 | MockWrite("GET / HTTP/1.1\r\n" |
| 3312 | "Host: www.example.org\r\n" |
| 3313 | "Connection: keep-alive\r\n\r\n"), |
| 3314 | }; |
| 3315 | |
| 3316 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3317 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3318 | |
| 3319 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3320 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3321 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3322 | MockRead(SYNCHRONOUS, "hello"), |
| 3323 | }; |
| 3324 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3325 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3326 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3327 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3328 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3329 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3330 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3331 | |
| 3332 | TestCompletionCallback callback1; |
| 3333 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3334 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3335 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3336 | |
| 3337 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3338 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3339 | |
| 3340 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3341 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3342 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3343 | log.GetEntries(&entries); |
| 3344 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3345 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3346 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3347 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3348 | entries, pos, |
| 3349 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3350 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3351 | |
| 3352 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3353 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3354 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3355 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3356 | EXPECT_EQ(407, response->headers->response_code()); |
| 3357 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3358 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3359 | |
| 3360 | LoadTimingInfo load_timing_info; |
| 3361 | // CONNECT requests and responses are handled at the connect job level, so |
| 3362 | // the transaction does not yet have a connection. |
| 3363 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3364 | |
| 3365 | TestCompletionCallback callback2; |
| 3366 | |
| 3367 | rv = |
| 3368 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3369 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3370 | |
| 3371 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3372 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3373 | |
| 3374 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3375 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3376 | |
| 3377 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3378 | EXPECT_EQ(200, response->headers->response_code()); |
| 3379 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3380 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3381 | |
| 3382 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3383 | EXPECT_FALSE(response->auth_challenge.has_value()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3384 | |
| 3385 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3386 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3387 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3388 | |
| 3389 | trans.reset(); |
| 3390 | session->CloseAllConnections(); |
| 3391 | } |
| 3392 | |
| 3393 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3394 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3395 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3396 | HttpRequestInfo request; |
| 3397 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3398 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3399 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3400 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3401 | request.traffic_annotation = |
| 3402 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3403 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3404 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3405 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3406 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3407 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3408 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3409 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3410 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3411 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3412 | // Since we have proxy, should try to establish tunnel. |
| 3413 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3414 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3415 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3416 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3417 | }; |
| 3418 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3419 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3420 | // connection. |
| 3421 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3422 | // No credentials. |
| 3423 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3424 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3425 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3426 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3427 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3428 | MockWrite data_writes2[] = { |
| 3429 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3430 | // be issuing -- the final header line contains the credentials. |
| 3431 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3432 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3433 | "Proxy-Connection: keep-alive\r\n" |
| 3434 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3435 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3436 | MockWrite("GET / HTTP/1.1\r\n" |
| 3437 | "Host: www.example.org\r\n" |
| 3438 | "Connection: keep-alive\r\n\r\n"), |
| 3439 | }; |
| 3440 | |
| 3441 | MockRead data_reads2[] = { |
| 3442 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3443 | |
| 3444 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3445 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3446 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3447 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3448 | }; |
| 3449 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3450 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3451 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3452 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3453 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3454 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3455 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3456 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3457 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3458 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3459 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3460 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3461 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3462 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3463 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3464 | |
| 3465 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3466 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3467 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3468 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3469 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3470 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3471 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3472 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3473 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3474 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3475 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3476 | |
| 3477 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3478 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3479 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3480 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3481 | EXPECT_EQ(407, response->headers->response_code()); |
| 3482 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3483 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3484 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3485 | LoadTimingInfo load_timing_info; |
| 3486 | // CONNECT requests and responses are handled at the connect job level, so |
| 3487 | // the transaction does not yet have a connection. |
| 3488 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3489 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3490 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3491 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3492 | rv = trans->RestartWithAuth( |
| 3493 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3494 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3495 | |
| 3496 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3497 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3498 | |
| 3499 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3500 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3501 | |
| 3502 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3503 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3504 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3505 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3506 | |
| 3507 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3508 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3509 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3510 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3511 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3512 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3513 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3514 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3515 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3516 | } |
| 3517 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3518 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3519 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3520 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3521 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3522 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3523 | // reused. See http://crbug.com/544255. |
| 3524 | for (int i = 0; i < 2; ++i) { |
| 3525 | HttpRequestInfo request; |
| 3526 | request.method = "GET"; |
| 3527 | request.url = GURL("https://www.example.org/"); |
| 3528 | // Ensure that proxy authentication is attempted even |
| 3529 | // when the no authentication data flag is set. |
| 3530 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3531 | request.traffic_annotation = |
| 3532 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3533 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3534 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3535 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3536 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3537 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3538 | BoundTestNetLog log; |
| 3539 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3540 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3541 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3542 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3543 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3544 | // Since we have proxy, should try to establish tunnel. |
| 3545 | MockWrite data_writes1[] = { |
| 3546 | MockWrite(ASYNC, 0, |
| 3547 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3548 | "Host: www.example.org:443\r\n" |
| 3549 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3550 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3551 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3552 | // be issuing -- the final header line contains the credentials. |
| 3553 | MockWrite(ASYNC, 3, |
| 3554 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3555 | "Host: www.example.org:443\r\n" |
| 3556 | "Proxy-Connection: keep-alive\r\n" |
| 3557 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3558 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3559 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3560 | // The proxy responds to the connect with a 407, using a persistent |
| 3561 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3562 | MockRead data_reads1[] = { |
| 3563 | // No credentials. |
| 3564 | MockRead(ASYNC, 1, |
| 3565 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3566 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3567 | "Proxy-Connection: keep-alive\r\n" |
| 3568 | "Content-Length: 10\r\n\r\n"), |
| 3569 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3570 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3571 | // Wrong credentials (wrong password). |
| 3572 | MockRead(ASYNC, 4, |
| 3573 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3574 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3575 | "Proxy-Connection: keep-alive\r\n" |
| 3576 | "Content-Length: 10\r\n\r\n"), |
| 3577 | // No response body because the test stops reading here. |
| 3578 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3579 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3580 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3581 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3582 | data1.set_busy_before_sync_reads(true); |
| 3583 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3584 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3585 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3586 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3587 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3588 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3589 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3590 | TestNetLogEntry::List entries; |
| 3591 | log.GetEntries(&entries); |
| 3592 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3593 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3594 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3595 | ExpectLogContainsSomewhere( |
| 3596 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3597 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3598 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3599 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3600 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3601 | ASSERT_TRUE(response); |
| 3602 | ASSERT_TRUE(response->headers); |
| 3603 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3604 | EXPECT_EQ(407, response->headers->response_code()); |
| 3605 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3606 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3607 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3608 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3609 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3610 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3611 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3612 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3613 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3614 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3615 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3616 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3617 | ASSERT_TRUE(response); |
| 3618 | ASSERT_TRUE(response->headers); |
| 3619 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3620 | EXPECT_EQ(407, response->headers->response_code()); |
| 3621 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3622 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3623 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3624 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3625 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3626 | // out of scope. |
| 3627 | session->CloseAllConnections(); |
| 3628 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3629 | } |
| 3630 | |
| 3631 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3632 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3633 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3634 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3635 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3636 | // reused. See http://crbug.com/544255. |
| 3637 | for (int i = 0; i < 2; ++i) { |
| 3638 | HttpRequestInfo request; |
| 3639 | request.method = "GET"; |
| 3640 | request.url = GURL("https://www.example.org/"); |
| 3641 | // Ensure that proxy authentication is attempted even |
| 3642 | // when the no authentication data flag is set. |
| 3643 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3644 | request.traffic_annotation = |
| 3645 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3646 | |
| 3647 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3648 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3649 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3650 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3651 | BoundTestNetLog log; |
| 3652 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3653 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3654 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3655 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3656 | |
| 3657 | // Since we have proxy, should try to establish tunnel. |
| 3658 | MockWrite data_writes1[] = { |
| 3659 | MockWrite(ASYNC, 0, |
| 3660 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3661 | "Host: www.example.org:443\r\n" |
| 3662 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3663 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3664 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3665 | // be issuing -- the final header line contains the credentials. |
| 3666 | MockWrite(ASYNC, 3, |
| 3667 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3668 | "Host: www.example.org:443\r\n" |
| 3669 | "Proxy-Connection: keep-alive\r\n" |
| 3670 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3671 | }; |
| 3672 | |
| 3673 | // The proxy responds to the connect with a 407, using a persistent |
| 3674 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3675 | MockRead data_reads1[] = { |
| 3676 | // No credentials. |
| 3677 | MockRead(ASYNC, 1, |
| 3678 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3679 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3680 | "Content-Length: 10\r\n\r\n"), |
| 3681 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3682 | |
| 3683 | // Wrong credentials (wrong password). |
| 3684 | MockRead(ASYNC, 4, |
| 3685 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3686 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3687 | "Content-Length: 10\r\n\r\n"), |
| 3688 | // No response body because the test stops reading here. |
| 3689 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3690 | }; |
| 3691 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3692 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3693 | data1.set_busy_before_sync_reads(true); |
| 3694 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3695 | |
| 3696 | TestCompletionCallback callback1; |
| 3697 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3698 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3699 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3700 | |
| 3701 | TestNetLogEntry::List entries; |
| 3702 | log.GetEntries(&entries); |
| 3703 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3704 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3705 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3706 | ExpectLogContainsSomewhere( |
| 3707 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3708 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3709 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3710 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3711 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3712 | ASSERT_TRUE(response); |
| 3713 | ASSERT_TRUE(response->headers); |
| 3714 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3715 | EXPECT_EQ(407, response->headers->response_code()); |
| 3716 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3717 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3718 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 3719 | EXPECT_FALSE(response->did_use_http_auth); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3720 | |
| 3721 | TestCompletionCallback callback2; |
| 3722 | |
| 3723 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3724 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3725 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3726 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3727 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3728 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3729 | ASSERT_TRUE(response); |
| 3730 | ASSERT_TRUE(response->headers); |
| 3731 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3732 | EXPECT_EQ(407, response->headers->response_code()); |
| 3733 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3734 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3735 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 3736 | EXPECT_TRUE(response->did_use_http_auth); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3737 | |
| 3738 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3739 | // out of scope. |
| 3740 | session->CloseAllConnections(); |
| 3741 | } |
| 3742 | } |
| 3743 | |
| 3744 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3745 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3746 | // the case the server sends extra data on the original socket, so it can't be |
| 3747 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3748 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3749 | HttpRequestInfo request; |
| 3750 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3751 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3752 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3753 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3754 | request.traffic_annotation = |
| 3755 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3756 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3757 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3758 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3759 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3760 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3761 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3762 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3763 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3764 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3765 | // Since we have proxy, should try to establish tunnel. |
| 3766 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3767 | MockWrite(ASYNC, 0, |
| 3768 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3769 | "Host: www.example.org:443\r\n" |
| 3770 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3771 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3772 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3773 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3774 | // extra data, so the socket cannot be reused. |
| 3775 | MockRead data_reads1[] = { |
| 3776 | // No credentials. |
| 3777 | MockRead(ASYNC, 1, |
| 3778 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3779 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3780 | "Content-Length: 10\r\n\r\n"), |
| 3781 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3782 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3783 | }; |
| 3784 | |
| 3785 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3786 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3787 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3788 | MockWrite(ASYNC, 0, |
| 3789 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3790 | "Host: www.example.org:443\r\n" |
| 3791 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3792 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3793 | |
| 3794 | MockWrite(ASYNC, 2, |
| 3795 | "GET / HTTP/1.1\r\n" |
| 3796 | "Host: www.example.org\r\n" |
| 3797 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3798 | }; |
| 3799 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3800 | MockRead data_reads2[] = { |
| 3801 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3802 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3803 | MockRead(ASYNC, 3, |
| 3804 | "HTTP/1.1 200 OK\r\n" |
| 3805 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3806 | "Content-Length: 5\r\n\r\n"), |
| 3807 | // No response body because the test stops reading here. |
| 3808 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3809 | }; |
| 3810 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3811 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3812 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3813 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3814 | SequencedSocketData data2(data_reads2, data_writes2); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3815 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3816 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3817 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3818 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3819 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3820 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3821 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3822 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3823 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3824 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3825 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3826 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3827 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3828 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3829 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3830 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3831 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3832 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3833 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3834 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3835 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3836 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3837 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3838 | ASSERT_TRUE(response); |
| 3839 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3840 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3841 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3842 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3843 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3844 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3845 | LoadTimingInfo load_timing_info; |
| 3846 | // CONNECT requests and responses are handled at the connect job level, so |
| 3847 | // the transaction does not yet have a connection. |
| 3848 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3849 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3850 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3851 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3852 | rv = |
| 3853 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3854 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3855 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3856 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3857 | EXPECT_EQ(200, response->headers->response_code()); |
| 3858 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3859 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3860 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3861 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3862 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3863 | |
| 3864 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3865 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3866 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3867 | |
| 3868 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3869 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3870 | } |
| 3871 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3872 | // Test the case a proxy closes a socket while the challenge body is being |
| 3873 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3874 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3875 | HttpRequestInfo request; |
| 3876 | request.method = "GET"; |
| 3877 | request.url = GURL("https://www.example.org/"); |
| 3878 | // Ensure that proxy authentication is attempted even |
| 3879 | // when the no authentication data flag is set. |
| 3880 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3881 | request.traffic_annotation = |
| 3882 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3883 | |
| 3884 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3885 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3886 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3887 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3888 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3889 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3890 | |
| 3891 | // Since we have proxy, should try to establish tunnel. |
| 3892 | MockWrite data_writes1[] = { |
| 3893 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3894 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3895 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3896 | }; |
| 3897 | |
| 3898 | // The proxy responds to the connect with a 407, using a persistent |
| 3899 | // connection. |
| 3900 | MockRead data_reads1[] = { |
| 3901 | // No credentials. |
| 3902 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3903 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3904 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3905 | // Server hands up in the middle of the body. |
| 3906 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3907 | }; |
| 3908 | |
| 3909 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3910 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3911 | // be issuing -- the final header line contains the credentials. |
| 3912 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3913 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3914 | "Proxy-Connection: keep-alive\r\n" |
| 3915 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3916 | |
| 3917 | MockWrite("GET / HTTP/1.1\r\n" |
| 3918 | "Host: www.example.org\r\n" |
| 3919 | "Connection: keep-alive\r\n\r\n"), |
| 3920 | }; |
| 3921 | |
| 3922 | MockRead data_reads2[] = { |
| 3923 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3924 | |
| 3925 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3926 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3927 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3928 | MockRead(SYNCHRONOUS, "hello"), |
| 3929 | }; |
| 3930 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3931 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3932 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3933 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3934 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3935 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3936 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3937 | |
| 3938 | TestCompletionCallback callback; |
| 3939 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3940 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3941 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3942 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3943 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3944 | ASSERT_TRUE(response); |
| 3945 | ASSERT_TRUE(response->headers); |
| 3946 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3947 | EXPECT_EQ(407, response->headers->response_code()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3948 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3949 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3950 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3951 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3952 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3953 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3954 | ASSERT_TRUE(response); |
| 3955 | ASSERT_TRUE(response->headers); |
| 3956 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3957 | EXPECT_EQ(200, response->headers->response_code()); |
| 3958 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3959 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3960 | EXPECT_EQ("hello", body); |
| 3961 | } |
| 3962 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3963 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3964 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3965 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3966 | HttpRequestInfo request; |
| 3967 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3968 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3969 | request.traffic_annotation = |
| 3970 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3971 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3972 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3973 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3974 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3975 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3976 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3977 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3978 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3979 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3980 | // Since we have proxy, should try to establish tunnel. |
| 3981 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3982 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3983 | "Host: www.example.org:443\r\n" |
| 3984 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3985 | }; |
| 3986 | |
| 3987 | // The proxy responds to the connect with a 407. |
| 3988 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3989 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3990 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3991 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3992 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3993 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3994 | }; |
| 3995 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3996 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3997 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3998 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3999 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4000 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4001 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4002 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4003 | |
| 4004 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4005 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4006 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4007 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4008 | ASSERT_TRUE(response); |
| 4009 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4010 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4011 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4012 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4013 | |
| 4014 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4015 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4016 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 4017 | |
| 4018 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 4019 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4020 | } |
| 4021 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4022 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 4023 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4024 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4025 | HttpRequestInfo request; |
| 4026 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4027 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4028 | request.traffic_annotation = |
| 4029 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4030 | |
| 4031 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4032 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4033 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4034 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4035 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4036 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4037 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4038 | |
| 4039 | // Since we have proxy, should try to establish tunnel. |
| 4040 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4041 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4042 | "Host: www.example.org:443\r\n" |
| 4043 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4044 | }; |
| 4045 | |
| 4046 | // The proxy responds to the connect with a 407. |
| 4047 | MockRead data_reads[] = { |
| 4048 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4049 | MockRead("X-Foo: bar\r\n"), |
| 4050 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 4051 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4052 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4053 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4054 | }; |
| 4055 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4056 | StaticSocketDataProvider data(data_reads, data_writes); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4057 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4058 | |
| 4059 | TestCompletionCallback callback; |
| 4060 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4061 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4062 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4063 | |
| 4064 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4065 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4066 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4067 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4068 | ASSERT_TRUE(response); |
| 4069 | ASSERT_TRUE(response->headers); |
| 4070 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4071 | EXPECT_EQ(407, response->headers->response_code()); |
| 4072 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4073 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 4074 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 4075 | |
| 4076 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4077 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4078 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4079 | |
| 4080 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 4081 | session->CloseAllConnections(); |
| 4082 | } |
| 4083 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4084 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 4085 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4086 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4087 | HttpRequestInfo request; |
| 4088 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4089 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4090 | request.traffic_annotation = |
| 4091 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4092 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4093 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4094 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4095 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4096 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4097 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4098 | MockWrite( |
| 4099 | "GET / HTTP/1.1\r\n" |
| 4100 | "Host: www.example.org\r\n" |
| 4101 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4102 | }; |
| 4103 | |
| 4104 | MockRead data_reads1[] = { |
| 4105 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 4106 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4107 | // Large content-length -- won't matter, as connection will be reset. |
| 4108 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4109 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4110 | }; |
| 4111 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4112 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4113 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4114 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4115 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4116 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4117 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4118 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4119 | |
| 4120 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4121 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4122 | } |
| 4123 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4124 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 4125 | // through a non-authenticating proxy. The request should fail with |
| 4126 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 4127 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 4128 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 4129 | // response came from the proxy or the server, so it is treated as if the proxy |
| 4130 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4131 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4132 | HttpRequestInfo request; |
| 4133 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4134 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4135 | request.traffic_annotation = |
| 4136 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4137 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4138 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4139 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4140 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4141 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4142 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4143 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4144 | // Since we have proxy, should try to establish tunnel. |
| 4145 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4146 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4147 | "Host: www.example.org:443\r\n" |
| 4148 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4149 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4150 | MockWrite("GET / HTTP/1.1\r\n" |
| 4151 | "Host: www.example.org\r\n" |
| 4152 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4153 | }; |
| 4154 | |
| 4155 | MockRead data_reads1[] = { |
| 4156 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4157 | |
| 4158 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 4159 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4160 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4161 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4162 | }; |
| 4163 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4164 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4165 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4166 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4167 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4168 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4169 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4170 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4171 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4172 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4173 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4174 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4175 | |
| 4176 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4177 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 4178 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4179 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4180 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4181 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 4182 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4183 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4184 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4185 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 4186 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4187 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4188 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4189 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4190 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4191 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4192 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 4193 | HttpRequestInfo request; |
| 4194 | request.method = "GET"; |
| 4195 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4196 | request.traffic_annotation = |
| 4197 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4198 | |
| 4199 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4200 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4201 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4202 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4203 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4204 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4205 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4206 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4207 | mock_handler->set_allows_default_credentials(true); |
| 4208 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4209 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4210 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4211 | |
| 4212 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4213 | NetLog net_log; |
| 4214 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4215 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4216 | |
| 4217 | // Since we have proxy, should try to establish tunnel. |
| 4218 | MockWrite data_writes1[] = { |
| 4219 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4220 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4221 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4222 | }; |
| 4223 | |
| 4224 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4225 | // connection. |
| 4226 | MockRead data_reads1[] = { |
| 4227 | // No credentials. |
| 4228 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4229 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4230 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4231 | }; |
| 4232 | |
| 4233 | // Since the first connection couldn't be reused, need to establish another |
| 4234 | // once given credentials. |
| 4235 | MockWrite data_writes2[] = { |
| 4236 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4237 | // be issuing -- the final header line contains the credentials. |
| 4238 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4239 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4240 | "Proxy-Connection: keep-alive\r\n" |
| 4241 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4242 | |
| 4243 | MockWrite("GET / HTTP/1.1\r\n" |
| 4244 | "Host: www.example.org\r\n" |
| 4245 | "Connection: keep-alive\r\n\r\n"), |
| 4246 | }; |
| 4247 | |
| 4248 | MockRead data_reads2[] = { |
| 4249 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4250 | |
| 4251 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4252 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4253 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4254 | MockRead(SYNCHRONOUS, "hello"), |
| 4255 | }; |
| 4256 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4257 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4258 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4259 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4260 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4261 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4262 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4263 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4264 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4265 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4266 | |
| 4267 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4268 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4269 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4270 | |
| 4271 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4272 | ASSERT_TRUE(response); |
| 4273 | ASSERT_TRUE(response->headers); |
| 4274 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 4275 | EXPECT_EQ(407, response->headers->response_code()); |
| 4276 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4277 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4278 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4279 | |
| 4280 | LoadTimingInfo load_timing_info; |
| 4281 | // CONNECT requests and responses are handled at the connect job level, so |
| 4282 | // the transaction does not yet have a connection. |
| 4283 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4284 | |
| 4285 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4286 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4287 | response = trans->GetResponseInfo(); |
| 4288 | ASSERT_TRUE(response); |
| 4289 | ASSERT_TRUE(response->headers); |
| 4290 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4291 | EXPECT_EQ(200, response->headers->response_code()); |
| 4292 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4293 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4294 | |
| 4295 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4296 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4297 | |
| 4298 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4299 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4300 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4301 | |
| 4302 | trans.reset(); |
| 4303 | session->CloseAllConnections(); |
| 4304 | } |
| 4305 | |
| 4306 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4307 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4308 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4309 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4310 | HttpRequestInfo request; |
| 4311 | request.method = "GET"; |
| 4312 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4313 | request.traffic_annotation = |
| 4314 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4315 | |
| 4316 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4317 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4318 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4319 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4320 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4321 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4322 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4323 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4324 | mock_handler->set_allows_default_credentials(true); |
| 4325 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4326 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4327 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4328 | |
| 4329 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4330 | NetLog net_log; |
| 4331 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4332 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4333 | |
| 4334 | // Should try to establish tunnel. |
| 4335 | MockWrite data_writes1[] = { |
| 4336 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4337 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4338 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4339 | |
| 4340 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4341 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4342 | "Proxy-Connection: keep-alive\r\n" |
| 4343 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4344 | }; |
| 4345 | |
| 4346 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4347 | // connection. |
| 4348 | MockRead data_reads1[] = { |
| 4349 | // No credentials. |
| 4350 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4351 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4352 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4353 | }; |
| 4354 | |
| 4355 | // Since the first connection was closed, need to establish another once given |
| 4356 | // credentials. |
| 4357 | MockWrite data_writes2[] = { |
| 4358 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4359 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4360 | "Proxy-Connection: keep-alive\r\n" |
| 4361 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4362 | |
| 4363 | MockWrite("GET / HTTP/1.1\r\n" |
| 4364 | "Host: www.example.org\r\n" |
| 4365 | "Connection: keep-alive\r\n\r\n"), |
| 4366 | }; |
| 4367 | |
| 4368 | MockRead data_reads2[] = { |
| 4369 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4370 | |
| 4371 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4372 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4373 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4374 | MockRead(SYNCHRONOUS, "hello"), |
| 4375 | }; |
| 4376 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4377 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4378 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4379 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4380 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4381 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4382 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4383 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4384 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4385 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4386 | |
| 4387 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4388 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4389 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4390 | |
| 4391 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4392 | ASSERT_TRUE(response); |
| 4393 | ASSERT_TRUE(response->headers); |
| 4394 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4395 | EXPECT_EQ(407, response->headers->response_code()); |
| 4396 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4397 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4398 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4399 | |
| 4400 | LoadTimingInfo load_timing_info; |
| 4401 | // CONNECT requests and responses are handled at the connect job level, so |
| 4402 | // the transaction does not yet have a connection. |
| 4403 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4404 | |
| 4405 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4406 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4407 | |
| 4408 | response = trans->GetResponseInfo(); |
| 4409 | ASSERT_TRUE(response); |
| 4410 | ASSERT_TRUE(response->headers); |
| 4411 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4412 | EXPECT_EQ(200, response->headers->response_code()); |
| 4413 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4414 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4415 | |
| 4416 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4417 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4418 | |
| 4419 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4420 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4421 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4422 | |
| 4423 | trans.reset(); |
| 4424 | session->CloseAllConnections(); |
| 4425 | } |
| 4426 | |
| 4427 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4428 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4429 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4430 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4431 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4432 | HttpRequestInfo request; |
| 4433 | request.method = "GET"; |
| 4434 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4435 | request.traffic_annotation = |
| 4436 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4437 | |
| 4438 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4439 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4440 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4441 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4442 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4443 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4444 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4445 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4446 | mock_handler->set_allows_default_credentials(true); |
| 4447 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4448 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4449 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4450 | |
| 4451 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4452 | NetLog net_log; |
| 4453 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4454 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4455 | |
| 4456 | // Should try to establish tunnel. |
| 4457 | MockWrite data_writes1[] = { |
| 4458 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4459 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4460 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4461 | |
| 4462 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4463 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4464 | "Proxy-Connection: keep-alive\r\n" |
| 4465 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4466 | }; |
| 4467 | |
| 4468 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4469 | // second request is sent. |
| 4470 | MockRead data_reads1[] = { |
| 4471 | // No credentials. |
| 4472 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4473 | MockRead("Content-Length: 0\r\n"), |
| 4474 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4475 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4476 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4477 | }; |
| 4478 | |
| 4479 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4480 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4481 | // request. |
| 4482 | MockWrite data_writes2[] = { |
| 4483 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4484 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4485 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4486 | }; |
| 4487 | |
| 4488 | // The proxy, having had more than enough of us, just hangs up. |
| 4489 | MockRead data_reads2[] = { |
| 4490 | // No credentials. |
| 4491 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4492 | }; |
| 4493 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4494 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4495 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4496 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4497 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4498 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4499 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4500 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4501 | |
| 4502 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4503 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4504 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4505 | |
| 4506 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4507 | ASSERT_TRUE(response); |
| 4508 | ASSERT_TRUE(response->headers); |
| 4509 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4510 | EXPECT_EQ(407, response->headers->response_code()); |
| 4511 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4512 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4513 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4514 | |
| 4515 | LoadTimingInfo load_timing_info; |
| 4516 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4517 | |
| 4518 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4519 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4520 | |
| 4521 | trans.reset(); |
| 4522 | session->CloseAllConnections(); |
| 4523 | } |
| 4524 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4525 | // This test exercises an odd edge case where the proxy closes the connection |
| 4526 | // after the authentication handshake is complete. Presumably this technique is |
| 4527 | // used in lieu of returning a 403 or 5xx status code when the authentication |
| 4528 | // succeeds, but the user is not authorized to connect to the destination |
| 4529 | // server. There's no standard for what a proxy should do to indicate a blocked |
| 4530 | // site. |
| 4531 | TEST_F(HttpNetworkTransactionTest, |
| 4532 | AuthAllowsDefaultCredentialsTunnelConnectionClosesBeforeBody) { |
| 4533 | HttpRequestInfo request; |
| 4534 | request.method = "GET"; |
| 4535 | request.url = GURL("https://www.example.org/"); |
| 4536 | request.traffic_annotation = |
| 4537 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4538 | |
| 4539 | // Configure against proxy server "myproxy:70". |
| 4540 | session_deps_.proxy_resolution_service = |
| 4541 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4542 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4543 | |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 4544 | // When TLS 1.3 is enabled, spurious connections are made as part of the SSL |
| 4545 | // version interference probes. |
| 4546 | // TODO(crbug.com/906668): Correctly handle version interference probes to |
| 4547 | // test TLS 1.3. |
| 4548 | SSLConfig config; |
| 4549 | config.version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
| 4550 | session_deps_.ssl_config_service = |
| 4551 | std::make_unique<TestSSLConfigService>(config); |
| 4552 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4553 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
| 4554 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4555 | |
| 4556 | // Create two mock AuthHandlers. This is because the transaction gets retried |
| 4557 | // after the first ERR_CONNECTION_CLOSED since it's ambiguous whether there |
| 4558 | // was a real network error. |
| 4559 | // |
| 4560 | // The handlers support both default and explicit credentials. The retry |
| 4561 | // mentioned above should be able to reuse the default identity. Thus there |
| 4562 | // should never be a need to prompt for explicit credentials. |
| 4563 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4564 | mock_handler->set_allows_default_credentials(true); |
| 4565 | mock_handler->set_allows_explicit_credentials(true); |
| 4566 | mock_handler->set_connection_based(true); |
| 4567 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4568 | HttpAuth::AUTH_PROXY); |
| 4569 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4570 | mock_handler->set_allows_default_credentials(true); |
| 4571 | mock_handler->set_allows_explicit_credentials(true); |
| 4572 | mock_handler->set_connection_based(true); |
| 4573 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4574 | HttpAuth::AUTH_PROXY); |
| 4575 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4576 | |
| 4577 | NetLog net_log; |
| 4578 | session_deps_.net_log = &net_log; |
| 4579 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4580 | |
| 4581 | // Data for both sockets. |
| 4582 | // |
| 4583 | // Writes are for the tunnel establishment attempts and the |
| 4584 | // authentication handshake. |
| 4585 | MockWrite data_writes1[] = { |
| 4586 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4587 | "Host: www.example.org:443\r\n" |
| 4588 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4589 | |
| 4590 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4591 | "Host: www.example.org:443\r\n" |
| 4592 | "Proxy-Connection: keep-alive\r\n" |
| 4593 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4594 | |
| 4595 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4596 | "Host: www.example.org:443\r\n" |
| 4597 | "Proxy-Connection: keep-alive\r\n" |
| 4598 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4599 | }; |
| 4600 | |
| 4601 | // The server side of the authentication handshake. Note that the response to |
| 4602 | // the final CONNECT request is ERR_CONNECTION_CLOSED. |
| 4603 | MockRead data_reads1[] = { |
| 4604 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4605 | MockRead("Content-Length: 0\r\n"), |
| 4606 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4607 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4608 | |
| 4609 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4610 | MockRead("Content-Length: 0\r\n"), |
| 4611 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4612 | MockRead("Proxy-Authenticate: Mock foo\r\n\r\n"), |
| 4613 | |
| 4614 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4615 | }; |
| 4616 | |
| 4617 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 4618 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4619 | |
| 4620 | // The second socket is for the reconnection attempt. Data is identical to the |
| 4621 | // first attempt. |
| 4622 | StaticSocketDataProvider data2(data_reads1, data_writes1); |
| 4623 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4624 | |
| 4625 | auto trans = |
| 4626 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4627 | |
| 4628 | TestCompletionCallback callback; |
| 4629 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4630 | |
| 4631 | // Two rounds per handshake. After one retry, the error is propagated up the |
| 4632 | // stack. |
| 4633 | for (int i = 0; i < 4; ++i) { |
| 4634 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4635 | |
| 4636 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4637 | ASSERT_TRUE(response); |
| 4638 | ASSERT_TRUE(response->headers); |
| 4639 | EXPECT_EQ(407, response->headers->response_code()); |
| 4640 | ASSERT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4641 | |
| 4642 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4643 | } |
| 4644 | |
| 4645 | // One shall be the number thou shalt retry, and the number of the retrying |
| 4646 | // shall be one. Two shalt thou not retry, neither retry thou zero, excepting |
| 4647 | // that thou then proceed to one. Three is right out. Once the number one, |
| 4648 | // being the first number, be reached, then lobbest thou thy |
| 4649 | // ERR_CONNECTION_CLOSED towards they network transaction, who shall snuff it. |
| 4650 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.GetResult(rv)); |
| 4651 | |
| 4652 | trans.reset(); |
| 4653 | session->CloseAllConnections(); |
| 4654 | } |
| 4655 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4656 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4657 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4658 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4659 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4660 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4661 | HttpRequestInfo request; |
| 4662 | request.method = "GET"; |
| 4663 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4664 | request.traffic_annotation = |
| 4665 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4666 | |
| 4667 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4668 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4669 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4670 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4671 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4672 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4673 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4674 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4675 | mock_handler->set_allows_default_credentials(true); |
| 4676 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4677 | HttpAuth::AUTH_PROXY); |
| 4678 | // Add another handler for the second challenge. It supports default |
| 4679 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4680 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4681 | mock_handler->set_allows_default_credentials(true); |
| 4682 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4683 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4684 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4685 | |
| 4686 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4687 | NetLog net_log; |
| 4688 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4689 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4690 | |
| 4691 | // Should try to establish tunnel. |
| 4692 | MockWrite data_writes1[] = { |
| 4693 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4694 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4695 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4696 | }; |
| 4697 | |
| 4698 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4699 | // connection. |
| 4700 | MockRead data_reads1[] = { |
| 4701 | // No credentials. |
| 4702 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4703 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4704 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4705 | }; |
| 4706 | |
| 4707 | // Since the first connection was closed, need to establish another once given |
| 4708 | // credentials. |
| 4709 | MockWrite data_writes2[] = { |
| 4710 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4711 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4712 | "Proxy-Connection: keep-alive\r\n" |
| 4713 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4714 | }; |
| 4715 | |
| 4716 | MockRead data_reads2[] = { |
| 4717 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4718 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4719 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4720 | }; |
| 4721 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4722 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4723 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4724 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4725 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4726 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4727 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4728 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4729 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4730 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4731 | |
| 4732 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4733 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4734 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4735 | |
| 4736 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4737 | ASSERT_TRUE(response); |
| 4738 | ASSERT_TRUE(response->headers); |
| 4739 | EXPECT_EQ(407, response->headers->response_code()); |
| 4740 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4741 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4742 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4743 | |
| 4744 | LoadTimingInfo load_timing_info; |
| 4745 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4746 | |
| 4747 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4748 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4749 | response = trans->GetResponseInfo(); |
| 4750 | ASSERT_TRUE(response); |
| 4751 | ASSERT_TRUE(response->headers); |
| 4752 | EXPECT_EQ(407, response->headers->response_code()); |
| 4753 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4754 | EXPECT_TRUE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4755 | |
| 4756 | trans.reset(); |
| 4757 | session->CloseAllConnections(); |
| 4758 | } |
| 4759 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4760 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4761 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4762 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4763 | // authentication handshake can continue with the same scheme but with a |
| 4764 | // different identity. |
| 4765 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4766 | HttpRequestInfo request; |
| 4767 | request.method = "GET"; |
| 4768 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4769 | request.traffic_annotation = |
| 4770 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4771 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4772 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4773 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4774 | |
| 4775 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4776 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4777 | mock_handler->set_allows_default_credentials(true); |
| 4778 | mock_handler->set_allows_explicit_credentials(true); |
| 4779 | mock_handler->set_connection_based(true); |
| 4780 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4781 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4782 | HttpAuth::AUTH_SERVER); |
| 4783 | |
| 4784 | // Add another handler for the second challenge. It supports default |
| 4785 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4786 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4787 | mock_handler->set_allows_default_credentials(true); |
| 4788 | mock_handler->set_allows_explicit_credentials(true); |
| 4789 | mock_handler->set_connection_based(true); |
| 4790 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4791 | HttpAuth::AUTH_SERVER); |
| 4792 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4793 | |
| 4794 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4795 | |
| 4796 | MockWrite data_writes1[] = { |
| 4797 | MockWrite("GET / HTTP/1.1\r\n" |
| 4798 | "Host: www.example.org\r\n" |
| 4799 | "Connection: keep-alive\r\n\r\n"), |
| 4800 | }; |
| 4801 | |
| 4802 | MockRead data_reads1[] = { |
| 4803 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4804 | "WWW-Authenticate: Mock\r\n" |
| 4805 | "Connection: keep-alive\r\n\r\n"), |
| 4806 | }; |
| 4807 | |
| 4808 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4809 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4810 | // transaction procceds without an authorization header. |
| 4811 | MockWrite data_writes2[] = { |
| 4812 | MockWrite("GET / HTTP/1.1\r\n" |
| 4813 | "Host: www.example.org\r\n" |
| 4814 | "Connection: keep-alive\r\n\r\n"), |
| 4815 | }; |
| 4816 | |
| 4817 | MockRead data_reads2[] = { |
| 4818 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4819 | "WWW-Authenticate: Mock\r\n" |
| 4820 | "Connection: keep-alive\r\n\r\n"), |
| 4821 | }; |
| 4822 | |
| 4823 | MockWrite data_writes3[] = { |
| 4824 | MockWrite("GET / HTTP/1.1\r\n" |
| 4825 | "Host: www.example.org\r\n" |
| 4826 | "Connection: keep-alive\r\n" |
| 4827 | "Authorization: auth_token\r\n\r\n"), |
| 4828 | }; |
| 4829 | |
| 4830 | MockRead data_reads3[] = { |
| 4831 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4832 | "Content-Length: 5\r\n" |
| 4833 | "Content-Type: text/plain\r\n" |
| 4834 | "Connection: keep-alive\r\n\r\n" |
| 4835 | "Hello"), |
| 4836 | }; |
| 4837 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4838 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4839 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4840 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4841 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4842 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4843 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4844 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4845 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4846 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4847 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4848 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4849 | |
| 4850 | TestCompletionCallback callback; |
| 4851 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4852 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4853 | |
| 4854 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4855 | ASSERT_TRUE(response); |
| 4856 | ASSERT_TRUE(response->headers); |
| 4857 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4858 | |
| 4859 | // The following three tests assert that an authentication challenge was |
| 4860 | // received and that the stack is ready to respond to the challenge using |
| 4861 | // ambient credentials. |
| 4862 | EXPECT_EQ(401, response->headers->response_code()); |
| 4863 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4864 | EXPECT_FALSE(response->auth_challenge.has_value()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4865 | |
| 4866 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4867 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4868 | response = trans->GetResponseInfo(); |
| 4869 | ASSERT_TRUE(response); |
| 4870 | ASSERT_TRUE(response->headers); |
| 4871 | |
| 4872 | // The following three tests assert that an authentication challenge was |
| 4873 | // received and that the stack needs explicit credentials before it is ready |
| 4874 | // to respond to the challenge. |
| 4875 | EXPECT_EQ(401, response->headers->response_code()); |
| 4876 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4877 | EXPECT_TRUE(response->auth_challenge.has_value()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4878 | |
| 4879 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4880 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4881 | response = trans->GetResponseInfo(); |
| 4882 | ASSERT_TRUE(response); |
| 4883 | ASSERT_TRUE(response->headers); |
| 4884 | EXPECT_EQ(200, response->headers->response_code()); |
| 4885 | |
| 4886 | trans.reset(); |
| 4887 | session->CloseAllConnections(); |
| 4888 | } |
| 4889 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4890 | // Proxy resolver that returns a proxy with the same host and port for different |
| 4891 | // schemes, based on the path of the URL being requests. |
| 4892 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 4893 | public: |
| 4894 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 4895 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 4896 | |
| 4897 | static std::string ProxyHostPortPairAsString() { return "proxy.test:10000"; } |
| 4898 | |
| 4899 | static HostPortPair ProxyHostPortPair() { |
| 4900 | return HostPortPair::FromString(ProxyHostPortPairAsString()); |
| 4901 | } |
| 4902 | |
| 4903 | // ProxyResolver implementation. |
| 4904 | int GetProxyForURL(const GURL& url, |
| 4905 | ProxyInfo* results, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4906 | CompletionOnceCallback callback, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4907 | std::unique_ptr<Request>* request, |
| 4908 | const NetLogWithSource& /*net_log*/) override { |
| 4909 | *results = ProxyInfo(); |
Ramin Halavati | 921731ea | 2018-03-16 08:24:57 | [diff] [blame] | 4910 | results->set_traffic_annotation( |
| 4911 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4912 | if (url.path() == "/socks4") { |
| 4913 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 4914 | return OK; |
| 4915 | } |
| 4916 | if (url.path() == "/socks5") { |
| 4917 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 4918 | return OK; |
| 4919 | } |
| 4920 | if (url.path() == "/http") { |
| 4921 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 4922 | return OK; |
| 4923 | } |
| 4924 | if (url.path() == "/https") { |
| 4925 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 4926 | return OK; |
| 4927 | } |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 4928 | if (url.path() == "/https_trusted") { |
| 4929 | results->UseProxyServer(ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 4930 | ProxyHostPortPair(), |
| 4931 | true /* is_trusted_proxy */)); |
| 4932 | return OK; |
| 4933 | } |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4934 | NOTREACHED(); |
| 4935 | return ERR_NOT_IMPLEMENTED; |
| 4936 | } |
| 4937 | |
| 4938 | private: |
| 4939 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 4940 | }; |
| 4941 | |
| 4942 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 4943 | : public ProxyResolverFactory { |
| 4944 | public: |
| 4945 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 4946 | : ProxyResolverFactory(false) {} |
| 4947 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4948 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 4949 | std::unique_ptr<ProxyResolver>* resolver, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4950 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4951 | std::unique_ptr<Request>* request) override { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4952 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 4953 | return OK; |
| 4954 | } |
| 4955 | |
| 4956 | private: |
| 4957 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 4958 | }; |
| 4959 | |
| 4960 | // 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] | 4961 | // same address, the connections are not grouped together. i.e., a request to |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4962 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 4963 | // request to foo.com using proxy.com as an HTTP proxy. |
| 4964 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4965 | session_deps_.proxy_resolution_service = |
| 4966 | std::make_unique<ProxyResolutionService>( |
| 4967 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 4968 | ProxyConfig::CreateAutoDetect(), TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 4969 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
| 4970 | nullptr); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4971 | |
| 4972 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4973 | |
| 4974 | MockWrite socks_writes[] = { |
| 4975 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 4976 | kSOCKS4OkRequestLocalHostPort80Length), |
| 4977 | MockWrite(SYNCHRONOUS, |
| 4978 | "GET /socks4 HTTP/1.1\r\n" |
| 4979 | "Host: test\r\n" |
| 4980 | "Connection: keep-alive\r\n\r\n"), |
| 4981 | }; |
| 4982 | MockRead socks_reads[] = { |
| 4983 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 4984 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4985 | "Connection: keep-alive\r\n" |
| 4986 | "Content-Length: 15\r\n\r\n" |
| 4987 | "SOCKS4 Response"), |
| 4988 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4989 | StaticSocketDataProvider socks_data(socks_reads, socks_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4990 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 4991 | |
| 4992 | const char kSOCKS5Request[] = { |
| 4993 | 0x05, // Version |
| 4994 | 0x01, // Command (CONNECT) |
| 4995 | 0x00, // Reserved |
| 4996 | 0x03, // Address type (DOMAINNAME) |
| 4997 | 0x04, // Length of domain (4) |
| 4998 | 't', 'e', 's', 't', // Domain string |
| 4999 | 0x00, 0x50, // 16-bit port (80) |
| 5000 | }; |
| 5001 | MockWrite socks5_writes[] = { |
| 5002 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5003 | MockWrite(ASYNC, kSOCKS5Request, base::size(kSOCKS5Request)), |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5004 | MockWrite(SYNCHRONOUS, |
| 5005 | "GET /socks5 HTTP/1.1\r\n" |
| 5006 | "Host: test\r\n" |
| 5007 | "Connection: keep-alive\r\n\r\n"), |
| 5008 | }; |
| 5009 | MockRead socks5_reads[] = { |
| 5010 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 5011 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 5012 | MockRead("HTTP/1.0 200 OK\r\n" |
| 5013 | "Connection: keep-alive\r\n" |
| 5014 | "Content-Length: 15\r\n\r\n" |
| 5015 | "SOCKS5 Response"), |
| 5016 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5017 | StaticSocketDataProvider socks5_data(socks5_reads, socks5_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5018 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 5019 | |
| 5020 | MockWrite http_writes[] = { |
| 5021 | MockWrite(SYNCHRONOUS, |
| 5022 | "GET http://test/http HTTP/1.1\r\n" |
| 5023 | "Host: test\r\n" |
| 5024 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5025 | }; |
| 5026 | MockRead http_reads[] = { |
| 5027 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5028 | "Proxy-Connection: keep-alive\r\n" |
| 5029 | "Content-Length: 13\r\n\r\n" |
| 5030 | "HTTP Response"), |
| 5031 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5032 | StaticSocketDataProvider http_data(http_reads, http_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5033 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 5034 | |
| 5035 | MockWrite https_writes[] = { |
| 5036 | MockWrite(SYNCHRONOUS, |
| 5037 | "GET http://test/https HTTP/1.1\r\n" |
| 5038 | "Host: test\r\n" |
| 5039 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5040 | }; |
| 5041 | MockRead https_reads[] = { |
| 5042 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5043 | "Proxy-Connection: keep-alive\r\n" |
| 5044 | "Content-Length: 14\r\n\r\n" |
| 5045 | "HTTPS Response"), |
| 5046 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5047 | StaticSocketDataProvider https_data(https_reads, https_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5048 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 5049 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 5050 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5051 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5052 | MockWrite https_trusted_writes[] = { |
| 5053 | MockWrite(SYNCHRONOUS, |
| 5054 | "GET http://test/https_trusted HTTP/1.1\r\n" |
| 5055 | "Host: test\r\n" |
| 5056 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5057 | }; |
| 5058 | MockRead https_trusted_reads[] = { |
| 5059 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5060 | "Proxy-Connection: keep-alive\r\n" |
| 5061 | "Content-Length: 22\r\n\r\n" |
| 5062 | "HTTPS Trusted Response"), |
| 5063 | }; |
| 5064 | StaticSocketDataProvider trusted_https_data(https_trusted_reads, |
| 5065 | https_trusted_writes); |
| 5066 | session_deps_.socket_factory->AddSocketDataProvider(&trusted_https_data); |
| 5067 | SSLSocketDataProvider ssl2(SYNCHRONOUS, OK); |
| 5068 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 5069 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5070 | struct TestCase { |
| 5071 | GURL url; |
| 5072 | std::string expected_response; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5073 | // 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] | 5074 | // after the test. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5075 | int expected_idle_socks4_sockets; |
| 5076 | int expected_idle_socks5_sockets; |
| 5077 | // How many idle sockets there should be in the HTTP/HTTPS proxy socket |
| 5078 | // pools after the test. |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5079 | int expected_idle_http_sockets; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5080 | int expected_idle_https_sockets; |
| 5081 | // How many idle sockets there should be in the HTTPS proxy socket pool with |
| 5082 | // the ProxyServer's |is_trusted_proxy| bit set after the test. |
| 5083 | int expected_idle_trusted_https_sockets; |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5084 | } const kTestCases[] = { |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5085 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0, 0, 0, 0}, |
| 5086 | {GURL("http://test/socks5"), "SOCKS5 Response", 1, 1, 0, 0, 0}, |
| 5087 | {GURL("http://test/http"), "HTTP Response", 1, 1, 1, 0, 0}, |
| 5088 | {GURL("http://test/https"), "HTTPS Response", 1, 1, 1, 1, 0}, |
| 5089 | {GURL("http://test/https_trusted"), "HTTPS Trusted Response", 1, 1, 1, 1, |
| 5090 | 1}, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5091 | }; |
| 5092 | |
| 5093 | for (const auto& test_case : kTestCases) { |
| 5094 | HttpRequestInfo request; |
| 5095 | request.method = "GET"; |
| 5096 | request.url = test_case.url; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5097 | request.traffic_annotation = |
| 5098 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5099 | std::unique_ptr<HttpNetworkTransaction> trans = |
| 5100 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 5101 | session.get()); |
| 5102 | TestCompletionCallback callback; |
| 5103 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 5104 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5105 | |
| 5106 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5107 | ASSERT_TRUE(response); |
| 5108 | ASSERT_TRUE(response->headers); |
| 5109 | EXPECT_EQ(200, response->headers->response_code()); |
| 5110 | std::string response_data; |
| 5111 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 5112 | EXPECT_EQ(test_case.expected_response, response_data); |
| 5113 | |
| 5114 | // Return the socket to the socket pool, so can make sure it's not used for |
| 5115 | // the next requests. |
| 5116 | trans.reset(); |
| 5117 | base::RunLoop().RunUntilIdle(); |
| 5118 | |
| 5119 | // Check the number of idle sockets in the pool, to make sure that used |
| 5120 | // sockets are indeed being returned to the socket pool. If each request |
| 5121 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 5122 | // pass. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5123 | EXPECT_EQ(test_case.expected_idle_socks4_sockets, |
| 5124 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5125 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5126 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5127 | ProxyServer(ProxyServer::SCHEME_SOCKS4, |
| 5128 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5129 | ProxyHostPortPair())) |
| 5130 | ->IdleSocketCount()); |
| 5131 | EXPECT_EQ(test_case.expected_idle_socks5_sockets, |
| 5132 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5133 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5134 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5135 | ProxyServer(ProxyServer::SCHEME_SOCKS5, |
| 5136 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5137 | ProxyHostPortPair())) |
| 5138 | ->IdleSocketCount()); |
| 5139 | EXPECT_EQ(test_case.expected_idle_http_sockets, |
| 5140 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5141 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5142 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5143 | ProxyServer(ProxyServer::SCHEME_HTTP, |
| 5144 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5145 | ProxyHostPortPair())) |
| 5146 | ->IdleSocketCount()); |
| 5147 | EXPECT_EQ(test_case.expected_idle_https_sockets, |
| 5148 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5149 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5150 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5151 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5152 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5153 | ProxyHostPortPair())) |
| 5154 | ->IdleSocketCount()); |
| 5155 | EXPECT_EQ(test_case.expected_idle_trusted_https_sockets, |
| 5156 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5157 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5158 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5159 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5160 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5161 | ProxyHostPortPair(), |
| 5162 | true /* is_trusted_proxy */)) |
| 5163 | ->IdleSocketCount()); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5164 | } |
| 5165 | } |
| 5166 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5167 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5168 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5169 | HttpRequestInfo request1; |
| 5170 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5171 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5172 | request1.traffic_annotation = |
| 5173 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5174 | |
| 5175 | HttpRequestInfo request2; |
| 5176 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5177 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5178 | request2.traffic_annotation = |
| 5179 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5180 | |
| 5181 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5182 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5183 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5184 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5185 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5186 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5187 | |
| 5188 | // Since we have proxy, should try to establish tunnel. |
| 5189 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5190 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5191 | "Host: www.example.org:443\r\n" |
| 5192 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5193 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5194 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5195 | "Host: www.example.org\r\n" |
| 5196 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5197 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5198 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5199 | "Host: www.example.org\r\n" |
| 5200 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5201 | }; |
| 5202 | |
| 5203 | // The proxy responds to the connect with a 407, using a persistent |
| 5204 | // connection. |
| 5205 | MockRead data_reads1[] = { |
| 5206 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5207 | |
| 5208 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5209 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5210 | MockRead(SYNCHRONOUS, "1"), |
| 5211 | |
| 5212 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5213 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5214 | MockRead(SYNCHRONOUS, "22"), |
| 5215 | }; |
| 5216 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5217 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5218 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5219 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5220 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5221 | |
| 5222 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5223 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5224 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5225 | |
| 5226 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5227 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5228 | |
| 5229 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5230 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5231 | |
| 5232 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5233 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5234 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5235 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5236 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5237 | |
| 5238 | LoadTimingInfo load_timing_info1; |
| 5239 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5240 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5241 | |
| 5242 | trans1.reset(); |
| 5243 | |
| 5244 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5245 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5246 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5247 | |
| 5248 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5249 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5250 | |
| 5251 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5252 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5253 | |
| 5254 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5255 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5256 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5257 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5258 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5259 | |
| 5260 | LoadTimingInfo load_timing_info2; |
| 5261 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5262 | TestLoadTimingReused(load_timing_info2); |
| 5263 | |
| 5264 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5265 | |
| 5266 | trans2.reset(); |
| 5267 | session->CloseAllConnections(); |
| 5268 | } |
| 5269 | |
| 5270 | // 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] | 5271 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5272 | HttpRequestInfo request1; |
| 5273 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5274 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5275 | request1.traffic_annotation = |
| 5276 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5277 | |
| 5278 | HttpRequestInfo request2; |
| 5279 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5280 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5281 | request2.traffic_annotation = |
| 5282 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5283 | |
| 5284 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5285 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5286 | ProxyResolutionService::CreateFixedFromPacResult( |
| 5287 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5288 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5289 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5290 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5291 | |
| 5292 | // Since we have proxy, should try to establish tunnel. |
| 5293 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5294 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5295 | "Host: www.example.org:443\r\n" |
| 5296 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5297 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5298 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5299 | "Host: www.example.org\r\n" |
| 5300 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5301 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5302 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5303 | "Host: www.example.org\r\n" |
| 5304 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5305 | }; |
| 5306 | |
| 5307 | // The proxy responds to the connect with a 407, using a persistent |
| 5308 | // connection. |
| 5309 | MockRead data_reads1[] = { |
| 5310 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5311 | |
| 5312 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5313 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5314 | MockRead(SYNCHRONOUS, "1"), |
| 5315 | |
| 5316 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5317 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5318 | MockRead(SYNCHRONOUS, "22"), |
| 5319 | }; |
| 5320 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5321 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5322 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5323 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5324 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5325 | |
| 5326 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5327 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5328 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5329 | |
| 5330 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5331 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5332 | |
| 5333 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5334 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5335 | |
| 5336 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5337 | ASSERT_TRUE(response1); |
| 5338 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5339 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5340 | |
| 5341 | LoadTimingInfo load_timing_info1; |
| 5342 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5343 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 5344 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 5345 | |
| 5346 | trans1.reset(); |
| 5347 | |
| 5348 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5349 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5350 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5351 | |
| 5352 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5353 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5354 | |
| 5355 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5356 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5357 | |
| 5358 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5359 | ASSERT_TRUE(response2); |
| 5360 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5361 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5362 | |
| 5363 | LoadTimingInfo load_timing_info2; |
| 5364 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5365 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 5366 | |
| 5367 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5368 | |
| 5369 | trans2.reset(); |
| 5370 | session->CloseAllConnections(); |
| 5371 | } |
| 5372 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5373 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5374 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5375 | HttpRequestInfo request; |
| 5376 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5377 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5378 | request.traffic_annotation = |
| 5379 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5380 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5381 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5382 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5383 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5384 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5385 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5386 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5387 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5388 | // Since we have proxy, should use full url |
| 5389 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5390 | MockWrite( |
| 5391 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5392 | "Host: www.example.org\r\n" |
| 5393 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5394 | }; |
| 5395 | |
| 5396 | MockRead data_reads1[] = { |
| 5397 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5398 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5399 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5400 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5401 | }; |
| 5402 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5403 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5404 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5405 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5406 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5407 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5408 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5409 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5410 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5411 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5412 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5413 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5414 | |
| 5415 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5416 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5417 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5418 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5419 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5420 | TestLoadTimingNotReused(load_timing_info, |
| 5421 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5422 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5423 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5424 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5425 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5426 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5427 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5428 | EXPECT_EQ(200, response->headers->response_code()); |
| 5429 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5430 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5431 | |
| 5432 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5433 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5434 | } |
| 5435 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5436 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5437 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5438 | HttpRequestInfo request; |
| 5439 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5440 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5441 | request.traffic_annotation = |
| 5442 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5443 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5444 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5445 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5446 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5447 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5448 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5449 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5450 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5451 | // fetch http://www.example.org/ via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5452 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5453 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5454 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5455 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5456 | spdy::SpdySerializedFrame resp( |
| 5457 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 5458 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5459 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5460 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5461 | }; |
| 5462 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5463 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5464 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5465 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5466 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5467 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5468 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5469 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5470 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5471 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5472 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5473 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5474 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5475 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5476 | |
| 5477 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5478 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5479 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5480 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5481 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5482 | TestLoadTimingNotReused(load_timing_info, |
| 5483 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5484 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5485 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5486 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5487 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5488 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5489 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5490 | |
| 5491 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5492 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5493 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5494 | } |
| 5495 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5496 | // Verifies that a session which races and wins against the owning transaction |
| 5497 | // (completing prior to host resolution), doesn't fail the transaction. |
| 5498 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5499 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5500 | HttpRequestInfo request; |
| 5501 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5502 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5503 | request.traffic_annotation = |
| 5504 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5505 | |
| 5506 | // Configure SPDY proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5507 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5508 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5509 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5510 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5511 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5512 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5513 | // Fetch http://www.example.org/ through the SPDY proxy. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5514 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5515 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5516 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5517 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5518 | spdy::SpdySerializedFrame resp( |
| 5519 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5520 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5521 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5522 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5523 | }; |
| 5524 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5525 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5526 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5527 | |
| 5528 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5529 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5530 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5531 | |
| 5532 | TestCompletionCallback callback1; |
| 5533 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5534 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5535 | |
| 5536 | // Stall the hostname resolution begun by the transaction. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5537 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5538 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5539 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5540 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5541 | |
| 5542 | // Race a session to the proxy, which completes first. |
| 5543 | session_deps_.host_resolver->set_ondemand_mode(false); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 5544 | SpdySessionKey key(HostPortPair("proxy", 70), ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 5545 | PRIVACY_MODE_DISABLED, |
| 5546 | SpdySessionKey::IsProxySession::kTrue, SocketTag()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5547 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 5548 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5549 | |
| 5550 | // Unstall the resolution begun by the transaction. |
| 5551 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5552 | session_deps_.host_resolver->ResolveAllPending(); |
| 5553 | |
| 5554 | EXPECT_FALSE(callback1.have_result()); |
| 5555 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5556 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5557 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5558 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5559 | ASSERT_TRUE(response); |
| 5560 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5561 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5562 | |
| 5563 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5564 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5565 | EXPECT_EQ(kUploadData, response_data); |
| 5566 | } |
| 5567 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5568 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5569 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5570 | HttpRequestInfo request; |
| 5571 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5572 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5573 | request.traffic_annotation = |
| 5574 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5575 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5576 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5577 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5578 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5579 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5580 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5581 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5582 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5583 | // The first request will be a bare GET, the second request will be a |
| 5584 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5585 | spdy_util_.set_default_url(request.url); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5586 | spdy::SpdySerializedFrame req_get( |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5587 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5588 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5589 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5590 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5591 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5592 | spdy::SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5593 | kExtraAuthorizationHeaders, base::size(kExtraAuthorizationHeaders) / 2, 3, |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5594 | LOWEST)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5595 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5596 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5597 | }; |
| 5598 | |
| 5599 | // The first response is a 407 proxy authentication challenge, and the second |
| 5600 | // response will be a 200 response since the second request includes a valid |
| 5601 | // Authorization header. |
| 5602 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5603 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5604 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5605 | spdy::SpdySerializedFrame resp_authentication( |
| 5606 | spdy_util_.ConstructSpdyReplyError( |
| 5607 | "407", kExtraAuthenticationHeaders, |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5608 | base::size(kExtraAuthenticationHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5609 | spdy::SpdySerializedFrame body_authentication( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5610 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5611 | spdy::SpdySerializedFrame resp_data( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5612 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5613 | spdy::SpdySerializedFrame body_data( |
| 5614 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5615 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5616 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5617 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5618 | CreateMockRead(resp_data, 4), |
| 5619 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5620 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5621 | }; |
| 5622 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5623 | SequencedSocketData data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5624 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5625 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5626 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5627 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5628 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5629 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5630 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5631 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5632 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5633 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5634 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5635 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5636 | |
| 5637 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5638 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5639 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5640 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5641 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5642 | ASSERT_TRUE(response); |
| 5643 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5644 | EXPECT_EQ(407, response->headers->response_code()); |
| 5645 | EXPECT_TRUE(response->was_fetched_via_spdy); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5646 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5647 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5648 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5649 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5650 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5651 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5652 | |
| 5653 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5654 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5655 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5656 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5657 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5658 | ASSERT_TRUE(response_restart); |
| 5659 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5660 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5661 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5662 | EXPECT_FALSE(response_restart->auth_challenge.has_value()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5663 | } |
| 5664 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5665 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5666 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5667 | HttpRequestInfo request; |
| 5668 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5669 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5670 | request.traffic_annotation = |
| 5671 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5672 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5673 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5674 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5675 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5676 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5677 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5678 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5679 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5680 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5681 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5682 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5683 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5684 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5685 | HostPortPair("www.example.org", 443))); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5686 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5687 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5688 | const char get[] = |
| 5689 | "GET / HTTP/1.1\r\n" |
| 5690 | "Host: www.example.org\r\n" |
| 5691 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5692 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5693 | spdy_util_.ConstructSpdyDataFrame(1, get, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5694 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5695 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5696 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 5697 | "Content-Length: 10\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5698 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5699 | spdy_util_.ConstructSpdyDataFrame(1, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5700 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5701 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5702 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5703 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5704 | |
| 5705 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5706 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5707 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5708 | }; |
| 5709 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5710 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5711 | CreateMockRead(conn_resp, 1, ASYNC), |
| 5712 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 5713 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 5714 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5715 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5716 | }; |
| 5717 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5718 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5719 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5720 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5721 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5722 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5723 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5724 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5725 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5726 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5727 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5728 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5729 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5730 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5731 | |
| 5732 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5733 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5734 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5735 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5736 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5737 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5738 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5739 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5740 | ASSERT_TRUE(response); |
| 5741 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5742 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5743 | |
| 5744 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5745 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5746 | EXPECT_EQ("1234567890", response_data); |
| 5747 | } |
| 5748 | |
| 5749 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5750 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5751 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5752 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5753 | HttpRequestInfo request; |
| 5754 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5755 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5756 | request.traffic_annotation = |
| 5757 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5758 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5759 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5760 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5761 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5762 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5763 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5764 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5765 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5766 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5767 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5768 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5769 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5770 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5771 | HostPortPair("www.example.org", 443))); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5772 | // fetch https://www.example.org/ via SPDY |
| 5773 | const char kMyUrl[] = "https://www.example.org/"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5774 | spdy::SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5775 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5776 | spdy::SpdySerializedFrame wrapped_get( |
| 5777 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 5778 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5779 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5780 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5781 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5782 | spdy::SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5783 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5784 | spdy::SpdySerializedFrame body( |
| 5785 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5786 | spdy::SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5787 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5788 | spdy::SpdySerializedFrame window_update_get_resp( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5789 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5790 | spdy::SpdySerializedFrame window_update_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5791 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5792 | |
| 5793 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5794 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5795 | CreateMockWrite(window_update_get_resp, 6), |
| 5796 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5797 | }; |
| 5798 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5799 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5800 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5801 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5802 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5803 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5804 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5805 | }; |
| 5806 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5807 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5808 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5809 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5810 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5811 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5812 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5813 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5814 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5815 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5816 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5817 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5818 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5819 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5820 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5821 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5822 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5823 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5824 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5825 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5826 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5827 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5828 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5829 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5830 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5831 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5832 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5833 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5834 | ASSERT_TRUE(response); |
| 5835 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5836 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5837 | |
| 5838 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5839 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5840 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5841 | } |
| 5842 | |
| 5843 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5844 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5845 | HttpRequestInfo request; |
| 5846 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5847 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5848 | request.traffic_annotation = |
| 5849 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5850 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5851 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5852 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5853 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5854 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5855 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5856 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5857 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5858 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5859 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5860 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5861 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5862 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5863 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5864 | spdy::SpdySerializedFrame get( |
| 5865 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5866 | |
| 5867 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5868 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5869 | }; |
| 5870 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5871 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
| 5872 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5873 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5874 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5875 | }; |
| 5876 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5877 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5878 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5879 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5880 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5881 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5882 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5883 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5884 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5885 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5886 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5887 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5888 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5889 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5890 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5891 | |
| 5892 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5893 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5894 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5895 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5896 | } |
| 5897 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5898 | // Test the case where a proxied H2 session doesn't exist when an auth challenge |
| 5899 | // is observed, but does exist by the time auth credentials are provided. |
| 5900 | // Proxy-Connection: Close is used so that there's a second DNS lookup, which is |
| 5901 | // what causes the existing H2 session to be noticed and reused. |
| 5902 | TEST_F(HttpNetworkTransactionTest, ProxiedH2SessionAppearsDuringAuth) { |
| 5903 | ProxyConfig proxy_config; |
| 5904 | proxy_config.set_auto_detect(true); |
| 5905 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 5906 | |
| 5907 | CapturingProxyResolver capturing_proxy_resolver; |
| 5908 | capturing_proxy_resolver.set_proxy_server( |
| 5909 | ProxyServer(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 70))); |
| 5910 | session_deps_.proxy_resolution_service = |
| 5911 | std::make_unique<ProxyResolutionService>( |
| 5912 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 5913 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 5914 | std::make_unique<CapturingProxyResolverFactory>( |
| 5915 | &capturing_proxy_resolver), |
| 5916 | nullptr); |
| 5917 | |
| 5918 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 5919 | |
| 5920 | const char kMyUrl[] = "https://www.example.org/"; |
| 5921 | spdy::SpdySerializedFrame get(spdy_util_.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 5922 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5923 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5924 | spdy::SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 5925 | |
| 5926 | spdy_util_.UpdateWithStreamDestruction(1); |
| 5927 | spdy::SpdySerializedFrame get2( |
| 5928 | spdy_util_.ConstructSpdyGet(kMyUrl, 3, LOWEST)); |
| 5929 | spdy::SpdySerializedFrame get_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5930 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5931 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
| 5932 | |
| 5933 | MockWrite auth_challenge_writes[] = { |
| 5934 | MockWrite(ASYNC, 0, |
| 5935 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5936 | "Host: www.example.org:443\r\n" |
| 5937 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5938 | }; |
| 5939 | |
| 5940 | MockRead auth_challenge_reads[] = { |
| 5941 | MockRead(ASYNC, 1, |
| 5942 | "HTTP/1.1 407 Authentication Required\r\n" |
| 5943 | "Content-Length: 0\r\n" |
| 5944 | "Proxy-Connection: close\r\n" |
| 5945 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
| 5946 | }; |
| 5947 | |
| 5948 | MockWrite spdy_writes[] = { |
| 5949 | MockWrite(ASYNC, 0, |
| 5950 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5951 | "Host: www.example.org:443\r\n" |
| 5952 | "Proxy-Connection: keep-alive\r\n" |
| 5953 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5954 | CreateMockWrite(get, 2), |
| 5955 | CreateMockWrite(get2, 5), |
| 5956 | }; |
| 5957 | |
| 5958 | MockRead spdy_reads[] = { |
| 5959 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 5960 | CreateMockRead(get_resp, 3, ASYNC), |
| 5961 | CreateMockRead(body, 4, ASYNC), |
| 5962 | CreateMockRead(get_resp2, 6, ASYNC), |
| 5963 | CreateMockRead(body2, 7, ASYNC), |
| 5964 | |
| 5965 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8), |
| 5966 | }; |
| 5967 | |
| 5968 | SequencedSocketData auth_challenge1(auth_challenge_reads, |
| 5969 | auth_challenge_writes); |
| 5970 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge1); |
| 5971 | |
| 5972 | SequencedSocketData auth_challenge2(auth_challenge_reads, |
| 5973 | auth_challenge_writes); |
| 5974 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge2); |
| 5975 | |
| 5976 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
| 5977 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5978 | |
| 5979 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5980 | ssl.next_proto = kProtoHTTP2; |
| 5981 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5982 | |
| 5983 | TestCompletionCallback callback; |
| 5984 | std::string response_data; |
| 5985 | |
| 5986 | // Run first request until an auth challenge is observed. |
| 5987 | HttpRequestInfo request1; |
| 5988 | request1.method = "GET"; |
| 5989 | request1.url = GURL(kMyUrl); |
| 5990 | request1.traffic_annotation = |
| 5991 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5992 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 5993 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 5994 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5995 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 5996 | ASSERT_TRUE(response); |
| 5997 | ASSERT_TRUE(response->headers); |
| 5998 | EXPECT_EQ(407, response->headers->response_code()); |
| 5999 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6000 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6001 | |
| 6002 | // Run second request until an auth challenge is observed. |
| 6003 | HttpRequestInfo request2; |
| 6004 | request2.method = "GET"; |
| 6005 | request2.url = GURL(kMyUrl); |
| 6006 | request2.traffic_annotation = |
| 6007 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6008 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6009 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 6010 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6011 | response = trans2.GetResponseInfo(); |
| 6012 | ASSERT_TRUE(response); |
| 6013 | ASSERT_TRUE(response->headers); |
| 6014 | EXPECT_EQ(407, response->headers->response_code()); |
| 6015 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6016 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6017 | |
| 6018 | // Now provide credentials for the first request, and wait for it to complete. |
| 6019 | rv = trans1.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6020 | rv = callback.GetResult(rv); |
| 6021 | EXPECT_THAT(rv, IsOk()); |
| 6022 | response = trans1.GetResponseInfo(); |
| 6023 | ASSERT_TRUE(response); |
| 6024 | ASSERT_TRUE(response->headers); |
| 6025 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6026 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6027 | EXPECT_EQ(kUploadData, response_data); |
| 6028 | |
| 6029 | // Now provide credentials for the second request. It should notice the |
| 6030 | // existing session, and reuse it. |
| 6031 | rv = trans2.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6032 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6033 | response = trans2.GetResponseInfo(); |
| 6034 | ASSERT_TRUE(response); |
| 6035 | ASSERT_TRUE(response->headers); |
| 6036 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6037 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6038 | EXPECT_EQ(kUploadData, response_data); |
| 6039 | } |
| 6040 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6041 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6042 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6043 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6044 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 6045 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6046 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6047 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6048 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6049 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6050 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6051 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6052 | |
| 6053 | HttpRequestInfo request1; |
| 6054 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6055 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6056 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6057 | request1.traffic_annotation = |
| 6058 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6059 | |
| 6060 | HttpRequestInfo request2; |
| 6061 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6062 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6063 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6064 | request2.traffic_annotation = |
| 6065 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6066 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6067 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6068 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6069 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6070 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6071 | spdy::SpdySerializedFrame conn_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6072 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6073 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6074 | // Fetch https://www.example.org/ via HTTP. |
| 6075 | const char get1[] = |
| 6076 | "GET / HTTP/1.1\r\n" |
| 6077 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6078 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6079 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6080 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6081 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6082 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6083 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6084 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6085 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6086 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6087 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6088 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6089 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6090 | // CONNECT to mail.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6091 | spdy::SpdyHeaderBlock connect2_block; |
| 6092 | connect2_block[spdy::kHttp2MethodHeader] = "CONNECT"; |
| 6093 | connect2_block[spdy::kHttp2AuthorityHeader] = "mail.example.org:443"; |
| 6094 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6095 | 3, std::move(connect2_block), HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6096 | false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 6097 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6098 | spdy::SpdySerializedFrame conn_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6099 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6100 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6101 | // Fetch https://mail.example.org/ via HTTP. |
| 6102 | const char get2[] = |
| 6103 | "GET / HTTP/1.1\r\n" |
| 6104 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6105 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6106 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6107 | spdy_util_.ConstructSpdyDataFrame(3, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6108 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6109 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6110 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6111 | spdy_util_.ConstructSpdyDataFrame(3, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6112 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6113 | spdy_util_.ConstructSpdyDataFrame(3, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6114 | |
| 6115 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6116 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6117 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6118 | }; |
| 6119 | |
| 6120 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6121 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6122 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 6123 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 6124 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 6125 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 6126 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 6127 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6128 | }; |
| 6129 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6130 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6131 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6132 | |
| 6133 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6134 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6135 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6136 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6137 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6138 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6139 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6140 | |
| 6141 | TestCompletionCallback callback; |
| 6142 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6143 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6144 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6145 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6146 | |
| 6147 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6148 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6149 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6150 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6151 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6152 | ASSERT_TRUE(response); |
| 6153 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6154 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6155 | |
| 6156 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6157 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6158 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6159 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6160 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6161 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6162 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6163 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6164 | |
| 6165 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6166 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6167 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 6168 | // to be created, so the socket's load timing looks like a fresh connection. |
| 6169 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6170 | |
| 6171 | // The requests should have different IDs, since they each are using their own |
| 6172 | // separate stream. |
| 6173 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6174 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6175 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6176 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6177 | } |
| 6178 | |
| 6179 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6180 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6181 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6182 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 6183 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6184 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6185 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6186 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6187 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6188 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6189 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6190 | |
| 6191 | HttpRequestInfo request1; |
| 6192 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6193 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6194 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6195 | request1.traffic_annotation = |
| 6196 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6197 | |
| 6198 | HttpRequestInfo request2; |
| 6199 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6200 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6201 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6202 | request2.traffic_annotation = |
| 6203 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6204 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6205 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6206 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6207 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6208 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6209 | spdy::SpdySerializedFrame conn_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6210 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6211 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6212 | // Fetch https://www.example.org/ via HTTP. |
| 6213 | const char get1[] = |
| 6214 | "GET / HTTP/1.1\r\n" |
| 6215 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6216 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6217 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6218 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6219 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6220 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6221 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6222 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6223 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6224 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6225 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6226 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6227 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6228 | // Fetch https://www.example.org/2 via HTTP. |
| 6229 | const char get2[] = |
| 6230 | "GET /2 HTTP/1.1\r\n" |
| 6231 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6232 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6233 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6234 | spdy_util_.ConstructSpdyDataFrame(1, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6235 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6236 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6237 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6238 | spdy_util_.ConstructSpdyDataFrame(1, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6239 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6240 | spdy_util_.ConstructSpdyDataFrame(1, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6241 | |
| 6242 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6243 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6244 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6245 | }; |
| 6246 | |
| 6247 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6248 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6249 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6250 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6251 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6252 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6253 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6254 | }; |
| 6255 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6256 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6257 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6258 | |
| 6259 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6260 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6261 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6262 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6263 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6264 | |
| 6265 | TestCompletionCallback callback; |
| 6266 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6267 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6268 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6269 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6270 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6271 | |
| 6272 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6273 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6274 | |
| 6275 | LoadTimingInfo load_timing_info; |
| 6276 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6277 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6278 | |
| 6279 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6280 | ASSERT_TRUE(response); |
| 6281 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6282 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6283 | |
| 6284 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6285 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6286 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6287 | trans.reset(); |
| 6288 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6289 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6290 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6291 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6292 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6293 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6294 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6295 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6296 | |
| 6297 | LoadTimingInfo load_timing_info2; |
| 6298 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 6299 | TestLoadTimingReused(load_timing_info2); |
| 6300 | |
| 6301 | // The requests should have the same ID. |
| 6302 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6303 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6304 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6305 | } |
| 6306 | |
| 6307 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 6308 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6309 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6310 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6311 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6312 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6313 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6314 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6315 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6316 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6317 | |
| 6318 | HttpRequestInfo request1; |
| 6319 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6320 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6321 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6322 | request1.traffic_annotation = |
| 6323 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6324 | |
| 6325 | HttpRequestInfo request2; |
| 6326 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6327 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6328 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6329 | request2.traffic_annotation = |
| 6330 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6331 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6332 | // http://www.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6333 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6334 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6335 | spdy::SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6336 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6337 | spdy::SpdySerializedFrame get_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6338 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6339 | spdy::SpdySerializedFrame body1( |
| 6340 | spdy_util_.ConstructSpdyDataFrame(1, "1", true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 6341 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6342 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6343 | // http://mail.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6344 | spdy::SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6345 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6346 | spdy::SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6347 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6348 | spdy::SpdySerializedFrame get_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6349 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6350 | spdy::SpdySerializedFrame body2( |
| 6351 | spdy_util_.ConstructSpdyDataFrame(3, "22", true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6352 | |
| 6353 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6354 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6355 | }; |
| 6356 | |
| 6357 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6358 | CreateMockRead(get_resp1, 1, ASYNC), |
| 6359 | CreateMockRead(body1, 2, ASYNC), |
| 6360 | CreateMockRead(get_resp2, 4, ASYNC), |
| 6361 | CreateMockRead(body2, 5, ASYNC), |
| 6362 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6363 | }; |
| 6364 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6365 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6366 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6367 | |
| 6368 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6369 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6370 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6371 | |
| 6372 | TestCompletionCallback callback; |
| 6373 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6374 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6375 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6376 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6377 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6378 | |
| 6379 | LoadTimingInfo load_timing_info; |
| 6380 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6381 | TestLoadTimingNotReused(load_timing_info, |
| 6382 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6383 | |
| 6384 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6385 | ASSERT_TRUE(response); |
| 6386 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6387 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6388 | |
| 6389 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6390 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6391 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 6392 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6393 | // Delete the first request, so the second one can reuse the socket. |
| 6394 | trans.reset(); |
| 6395 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6396 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6397 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6398 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6399 | |
| 6400 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6401 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6402 | TestLoadTimingReused(load_timing_info2); |
| 6403 | |
| 6404 | // The requests should have the same ID. |
| 6405 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6406 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6407 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6408 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6409 | } |
| 6410 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6411 | // Test that an HTTP/2 CONNECT through an HTTPS Proxy to a HTTP/2 server and a |
| 6412 | // direct (non-proxied) request to the proxy server are not pooled, as that |
| 6413 | // would break socket pool isolation. |
| 6414 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation1) { |
| 6415 | ProxyConfig proxy_config; |
| 6416 | proxy_config.set_auto_detect(true); |
| 6417 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6418 | |
| 6419 | CapturingProxyResolver capturing_proxy_resolver; |
| 6420 | session_deps_.proxy_resolution_service = |
| 6421 | std::make_unique<ProxyResolutionService>( |
| 6422 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6423 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6424 | std::make_unique<CapturingProxyResolverFactory>( |
| 6425 | &capturing_proxy_resolver), |
| 6426 | nullptr); |
| 6427 | |
| 6428 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6429 | |
| 6430 | SpdyTestUtil spdy_util1; |
| 6431 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6432 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6433 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6434 | HostPortPair("www.example.org", 443))); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6435 | // fetch https://www.example.org/ via HTTP/2. |
| 6436 | const char kMyUrl[] = "https://www.example.org/"; |
| 6437 | spdy::SpdySerializedFrame get(spdy_util1.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6438 | spdy::SpdySerializedFrame wrapped_get( |
| 6439 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6440 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6441 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6442 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6443 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6444 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6445 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6446 | spdy::SpdySerializedFrame body(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6447 | spdy::SpdySerializedFrame wrapped_body( |
| 6448 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6449 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6450 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6451 | spdy::SpdySerializedFrame window_update_body( |
| 6452 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6453 | |
| 6454 | MockWrite spdy_writes1[] = { |
| 6455 | CreateMockWrite(connect, 0), |
| 6456 | CreateMockWrite(wrapped_get, 2), |
| 6457 | CreateMockWrite(window_update_get_resp, 6), |
| 6458 | CreateMockWrite(window_update_body, 7), |
| 6459 | }; |
| 6460 | |
| 6461 | MockRead spdy_reads1[] = { |
| 6462 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6463 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6464 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6465 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6466 | MockRead(ASYNC, 0, 8), |
| 6467 | }; |
| 6468 | |
| 6469 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6470 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6471 | |
| 6472 | // Fetch https://proxy:70/ via HTTP/2. Needs a new SpdyTestUtil, since it uses |
| 6473 | // a new pipe. |
| 6474 | SpdyTestUtil spdy_util2; |
| 6475 | spdy::SpdySerializedFrame req( |
| 6476 | spdy_util2.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6477 | MockWrite spdy_writes2[] = {CreateMockWrite(req, 0)}; |
| 6478 | |
| 6479 | spdy::SpdySerializedFrame resp( |
| 6480 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6481 | spdy::SpdySerializedFrame data(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6482 | MockRead spdy_reads2[] = { |
| 6483 | CreateMockRead(resp, 1), |
| 6484 | CreateMockRead(data, 2), |
| 6485 | MockRead(ASYNC, 0, 3), |
| 6486 | }; |
| 6487 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6488 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6489 | |
| 6490 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6491 | ssl.next_proto = kProtoHTTP2; |
| 6492 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6493 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6494 | ssl2.next_proto = kProtoHTTP2; |
| 6495 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6496 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6497 | ssl3.next_proto = kProtoHTTP2; |
| 6498 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6499 | |
| 6500 | TestCompletionCallback callback; |
| 6501 | std::string response_data; |
| 6502 | |
| 6503 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6504 | capturing_proxy_resolver.set_proxy_server( |
| 6505 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6506 | HttpRequestInfo request1; |
| 6507 | request1.method = "GET"; |
| 6508 | request1.url = GURL("https://www.example.org/"); |
| 6509 | request1.traffic_annotation = |
| 6510 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6511 | |
| 6512 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6513 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 6514 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6515 | |
| 6516 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6517 | base::RunLoop().RunUntilIdle(); |
| 6518 | // Now allow the read of the response to complete. |
| 6519 | spdy_data1.Resume(); |
| 6520 | rv = callback.WaitForResult(); |
| 6521 | EXPECT_THAT(rv, IsOk()); |
| 6522 | |
| 6523 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 6524 | ASSERT_TRUE(response); |
| 6525 | ASSERT_TRUE(response->headers); |
| 6526 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6527 | |
| 6528 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6529 | EXPECT_EQ(kUploadData, response_data); |
| 6530 | RunUntilIdle(); |
| 6531 | |
| 6532 | // Make a direct HTTP/2 request to proxy:70. |
| 6533 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6534 | HttpRequestInfo request2; |
| 6535 | request2.method = "GET"; |
| 6536 | request2.url = GURL("https://proxy:70/"); |
| 6537 | request2.traffic_annotation = |
| 6538 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6539 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6540 | EXPECT_THAT(callback.GetResult(trans2.Start(&request2, callback.callback(), |
| 6541 | NetLogWithSource())), |
| 6542 | IsOk()); |
| 6543 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6544 | } |
| 6545 | |
| 6546 | // Same as above, but reverse request order, since the code to check for an |
| 6547 | // existing session is different for tunnels and direct connections. |
| 6548 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation2) { |
| 6549 | // Configure against https proxy server "myproxy:80". |
| 6550 | ProxyConfig proxy_config; |
| 6551 | proxy_config.set_auto_detect(true); |
| 6552 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6553 | |
| 6554 | CapturingProxyResolver capturing_proxy_resolver; |
| 6555 | session_deps_.proxy_resolution_service = |
| 6556 | std::make_unique<ProxyResolutionService>( |
| 6557 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6558 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6559 | std::make_unique<CapturingProxyResolverFactory>( |
| 6560 | &capturing_proxy_resolver), |
| 6561 | nullptr); |
| 6562 | |
| 6563 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6564 | // Fetch https://proxy:70/ via HTTP/2. |
| 6565 | SpdyTestUtil spdy_util1; |
| 6566 | spdy::SpdySerializedFrame req( |
| 6567 | spdy_util1.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6568 | MockWrite spdy_writes1[] = {CreateMockWrite(req, 0)}; |
| 6569 | |
| 6570 | spdy::SpdySerializedFrame resp( |
| 6571 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6572 | spdy::SpdySerializedFrame data(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6573 | MockRead spdy_reads1[] = { |
| 6574 | CreateMockRead(resp, 1), |
| 6575 | CreateMockRead(data, 2), |
| 6576 | MockRead(ASYNC, 0, 3), |
| 6577 | }; |
| 6578 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6579 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6580 | |
| 6581 | SpdyTestUtil spdy_util2; |
| 6582 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6583 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6584 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6585 | HostPortPair("www.example.org", 443))); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6586 | // fetch https://www.example.org/ via HTTP/2. |
| 6587 | const char kMyUrl[] = "https://www.example.org/"; |
| 6588 | spdy::SpdySerializedFrame get(spdy_util2.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6589 | spdy::SpdySerializedFrame wrapped_get( |
| 6590 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6591 | spdy::SpdySerializedFrame conn_resp( |
| 6592 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6593 | spdy::SpdySerializedFrame get_resp( |
| 6594 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6595 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6596 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6597 | spdy::SpdySerializedFrame body(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6598 | spdy::SpdySerializedFrame wrapped_body( |
| 6599 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6600 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6601 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6602 | spdy::SpdySerializedFrame window_update_body( |
| 6603 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6604 | |
| 6605 | MockWrite spdy_writes2[] = { |
| 6606 | CreateMockWrite(connect, 0), |
| 6607 | CreateMockWrite(wrapped_get, 2), |
| 6608 | CreateMockWrite(window_update_get_resp, 6), |
| 6609 | CreateMockWrite(window_update_body, 7), |
| 6610 | }; |
| 6611 | |
| 6612 | MockRead spdy_reads2[] = { |
| 6613 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6614 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6615 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6616 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6617 | MockRead(ASYNC, 0, 8), |
| 6618 | }; |
| 6619 | |
| 6620 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6621 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6622 | |
| 6623 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6624 | ssl.next_proto = kProtoHTTP2; |
| 6625 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6626 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6627 | ssl2.next_proto = kProtoHTTP2; |
| 6628 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6629 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6630 | ssl3.next_proto = kProtoHTTP2; |
| 6631 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6632 | |
| 6633 | TestCompletionCallback callback; |
| 6634 | std::string response_data; |
| 6635 | |
| 6636 | // Make a direct HTTP/2 request to proxy:70. |
| 6637 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6638 | HttpRequestInfo request1; |
| 6639 | request1.method = "GET"; |
| 6640 | request1.url = GURL("https://proxy:70/"); |
| 6641 | request1.traffic_annotation = |
| 6642 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6643 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6644 | EXPECT_THAT(callback.GetResult(trans1.Start(&request1, callback.callback(), |
| 6645 | NetLogWithSource())), |
| 6646 | IsOk()); |
| 6647 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6648 | RunUntilIdle(); |
| 6649 | |
| 6650 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6651 | capturing_proxy_resolver.set_proxy_server( |
| 6652 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6653 | HttpRequestInfo request2; |
| 6654 | request2.method = "GET"; |
| 6655 | request2.url = GURL("https://www.example.org/"); |
| 6656 | request2.traffic_annotation = |
| 6657 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6658 | |
| 6659 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6660 | int rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 6661 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6662 | |
| 6663 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6664 | base::RunLoop().RunUntilIdle(); |
| 6665 | // Now allow the read of the response to complete. |
| 6666 | spdy_data2.Resume(); |
| 6667 | rv = callback.WaitForResult(); |
| 6668 | EXPECT_THAT(rv, IsOk()); |
| 6669 | |
| 6670 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 6671 | ASSERT_TRUE(response2); |
| 6672 | ASSERT_TRUE(response2->headers); |
| 6673 | EXPECT_EQ("HTTP/1.1 200", response2->headers->GetStatusLine()); |
| 6674 | |
| 6675 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6676 | EXPECT_EQ(kUploadData, response_data); |
| 6677 | } |
| 6678 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6679 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6680 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6681 | HttpRequestInfo request; |
| 6682 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6683 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6684 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 6685 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6686 | request.traffic_annotation = |
| 6687 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6688 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6689 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6690 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6691 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6692 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6693 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6694 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6695 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6696 | // Since we have proxy, should use full url |
| 6697 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6698 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6699 | "Host: www.example.org\r\n" |
| 6700 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6701 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6702 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6703 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6704 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6705 | "Host: www.example.org\r\n" |
| 6706 | "Proxy-Connection: keep-alive\r\n" |
| 6707 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6708 | }; |
| 6709 | |
| 6710 | // The proxy responds to the GET with a 407, using a persistent |
| 6711 | // connection. |
| 6712 | MockRead data_reads1[] = { |
| 6713 | // No credentials. |
| 6714 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 6715 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6716 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 6717 | MockRead("Content-Length: 0\r\n\r\n"), |
| 6718 | |
| 6719 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6720 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6721 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6722 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6723 | }; |
| 6724 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6725 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6726 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6727 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6728 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6729 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6730 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6731 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6732 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6733 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6734 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6735 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6736 | |
| 6737 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6738 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6739 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6740 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6741 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6742 | TestLoadTimingNotReused(load_timing_info, |
| 6743 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6744 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6745 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6746 | ASSERT_TRUE(response); |
| 6747 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6748 | EXPECT_EQ(407, response->headers->response_code()); |
| 6749 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6750 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge)); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 6751 | EXPECT_FALSE(response->did_use_http_auth); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6752 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6753 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6754 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6755 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6756 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6757 | |
| 6758 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6759 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6760 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6761 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6762 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6763 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 6764 | TestLoadTimingReused(load_timing_info); |
| 6765 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6766 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6767 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6768 | |
| 6769 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6770 | EXPECT_EQ(200, response->headers->response_code()); |
| 6771 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6772 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 6773 | EXPECT_TRUE(response->did_use_http_auth); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6774 | |
| 6775 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6776 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6777 | } |
| 6778 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6779 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6780 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6781 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6782 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6783 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6784 | request.traffic_annotation = |
| 6785 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6786 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6787 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6788 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6789 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6790 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6791 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6792 | // Since we have proxy, should try to establish tunnel. |
| 6793 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6794 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6795 | "Host: www.example.org:443\r\n" |
| 6796 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6797 | }; |
| 6798 | |
| 6799 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6800 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 6801 | // No response body because the test stops reading here. |
| 6802 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6803 | }; |
| 6804 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6805 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6806 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6807 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6808 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6809 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6810 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6811 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6812 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6813 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6814 | |
| 6815 | rv = callback.WaitForResult(); |
| 6816 | EXPECT_EQ(expected_status, rv); |
| 6817 | } |
| 6818 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6819 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 6820 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6821 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6822 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6823 | } |
| 6824 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6825 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6826 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 6827 | } |
| 6828 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6829 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6830 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 6831 | } |
| 6832 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6833 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6834 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 6835 | } |
| 6836 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6837 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6838 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 6839 | } |
| 6840 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6841 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6842 | ConnectStatusHelper( |
| 6843 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 6844 | } |
| 6845 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6846 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6847 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 6848 | } |
| 6849 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6850 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6851 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 6852 | } |
| 6853 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6854 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6855 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 6856 | } |
| 6857 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6858 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6859 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 6860 | } |
| 6861 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6862 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6863 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 6864 | } |
| 6865 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6866 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6867 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 6868 | } |
| 6869 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6870 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6871 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 6872 | } |
| 6873 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6874 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6875 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 6876 | } |
| 6877 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6878 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6879 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 6880 | } |
| 6881 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6882 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6883 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 6884 | } |
| 6885 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6886 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6887 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 6888 | } |
| 6889 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6890 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 6891 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 6892 | } |
| 6893 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6894 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6895 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 6896 | } |
| 6897 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6898 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6899 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 6900 | } |
| 6901 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6902 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6903 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 6904 | } |
| 6905 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6906 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6907 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 6908 | } |
| 6909 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6910 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6911 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 6912 | } |
| 6913 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6914 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6915 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 6916 | } |
| 6917 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6918 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6919 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 6920 | } |
| 6921 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6922 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6923 | ConnectStatusHelperWithExpectedStatus( |
| 6924 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 6925 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6926 | } |
| 6927 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6928 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6929 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 6930 | } |
| 6931 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6932 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6933 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 6934 | } |
| 6935 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6936 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6937 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 6938 | } |
| 6939 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6940 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6941 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 6942 | } |
| 6943 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6944 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6945 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 6946 | } |
| 6947 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6948 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6949 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 6950 | } |
| 6951 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6952 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6953 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 6954 | } |
| 6955 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6956 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6957 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 6958 | } |
| 6959 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6960 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6961 | ConnectStatusHelper( |
| 6962 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 6963 | } |
| 6964 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6965 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6966 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 6967 | } |
| 6968 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6969 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6970 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 6971 | } |
| 6972 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6973 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6974 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 6975 | } |
| 6976 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6977 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6978 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 6979 | } |
| 6980 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6981 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6982 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 6983 | } |
| 6984 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6985 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6986 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 6987 | } |
| 6988 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6989 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6990 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 6991 | } |
| 6992 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6993 | // Test the flow when both the proxy server AND origin server require |
| 6994 | // authentication. Again, this uses basic auth for both since that is |
| 6995 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6996 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6997 | HttpRequestInfo request; |
| 6998 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6999 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7000 | request.traffic_annotation = |
| 7001 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7002 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7003 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 7004 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 7005 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7006 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7007 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7008 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7009 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7010 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7011 | MockWrite( |
| 7012 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7013 | "Host: www.example.org\r\n" |
| 7014 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7015 | }; |
| 7016 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7017 | MockRead data_reads1[] = { |
| 7018 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 7019 | // Give a couple authenticate options (only the middle one is actually |
| 7020 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 7021 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7022 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7023 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 7024 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7025 | // Large content-length -- won't matter, as connection will be reset. |
| 7026 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7027 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7028 | }; |
| 7029 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7030 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7031 | // request we should be issuing -- the final header line contains the |
| 7032 | // proxy's credentials. |
| 7033 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7034 | MockWrite( |
| 7035 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7036 | "Host: www.example.org\r\n" |
| 7037 | "Proxy-Connection: keep-alive\r\n" |
| 7038 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7039 | }; |
| 7040 | |
| 7041 | // Now the proxy server lets the request pass through to origin server. |
| 7042 | // The origin server responds with a 401. |
| 7043 | MockRead data_reads2[] = { |
| 7044 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7045 | // Note: We are using the same realm-name as the proxy server. This is |
| 7046 | // completely valid, as realms are unique across hosts. |
| 7047 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7048 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7049 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7050 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7051 | }; |
| 7052 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7053 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7054 | // the credentials for both the proxy and origin server. |
| 7055 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7056 | MockWrite( |
| 7057 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7058 | "Host: www.example.org\r\n" |
| 7059 | "Proxy-Connection: keep-alive\r\n" |
| 7060 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 7061 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7062 | }; |
| 7063 | |
| 7064 | // Lastly we get the desired content. |
| 7065 | MockRead data_reads3[] = { |
| 7066 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7067 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7068 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7069 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7070 | }; |
| 7071 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7072 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7073 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7074 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7075 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7076 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7077 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7078 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7079 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7080 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7081 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7082 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7083 | |
| 7084 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7085 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7086 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7087 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7088 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7089 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7090 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7091 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7092 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7093 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7094 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7095 | |
| 7096 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7097 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7098 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7099 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7100 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7101 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7102 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7103 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7104 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7105 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7106 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7107 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7108 | |
| 7109 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7110 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7111 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7112 | response = trans.GetResponseInfo(); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7113 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7114 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7115 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7116 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7117 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 7118 | // can't hook into its internals to cause it to generate predictable NTLM |
| 7119 | // authorization headers. |
| 7120 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7121 | // The NTLM authentication unit tests are based on known test data from the |
| 7122 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 7123 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 7124 | // for the implementation and testing of the protocol. |
| 7125 | // |
| 7126 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7127 | |
| 7128 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7129 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7130 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7131 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7132 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7133 | request.traffic_annotation = |
| 7134 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7135 | |
| 7136 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7137 | // to other auth schemes. |
| 7138 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7139 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7140 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7141 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7142 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7143 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7144 | // Generate the NTLM messages based on known test data. |
| 7145 | std::string negotiate_msg; |
| 7146 | std::string challenge_msg; |
| 7147 | std::string authenticate_msg; |
| 7148 | base::Base64Encode( |
| 7149 | base::StringPiece( |
| 7150 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7151 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7152 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7153 | base::Base64Encode( |
| 7154 | base::StringPiece( |
| 7155 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7156 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7157 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7158 | base::Base64Encode( |
| 7159 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7160 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7161 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7162 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7163 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7164 | &authenticate_msg); |
| 7165 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7166 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7167 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7168 | "Host: server\r\n" |
| 7169 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7170 | }; |
| 7171 | |
| 7172 | MockRead data_reads1[] = { |
| 7173 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7174 | // Negotiate and NTLM are often requested together. However, we only want |
| 7175 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7176 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7177 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7178 | MockRead("Connection: close\r\n"), |
| 7179 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7180 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7181 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7182 | }; |
| 7183 | |
| 7184 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7185 | // After restarting with a null identity, this is the |
| 7186 | // request we should be issuing -- the final header line contains a Type |
| 7187 | // 1 message. |
| 7188 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7189 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7190 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7191 | "Authorization: NTLM "), |
| 7192 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7193 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7194 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7195 | // (using correct credentials). The second request continues on the |
| 7196 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7197 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7198 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7199 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7200 | "Authorization: NTLM "), |
| 7201 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7202 | }; |
| 7203 | |
| 7204 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7205 | // The origin server responds with a Type 2 message. |
| 7206 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7207 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7208 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7209 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7210 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7211 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7212 | // Lastly we get the desired content. |
| 7213 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7214 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7215 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7216 | }; |
| 7217 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7218 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7219 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7220 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7221 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7222 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7223 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7224 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7225 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7226 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7227 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7228 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7229 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7230 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7231 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7232 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7233 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7234 | |
| 7235 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7236 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7237 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7238 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7239 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7240 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7241 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7242 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7243 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7244 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7245 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7246 | rv = trans.RestartWithAuth( |
| 7247 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7248 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7249 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7250 | |
| 7251 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7252 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7253 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7254 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7255 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7256 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7257 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7258 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7259 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7260 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7261 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7262 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7263 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7264 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7265 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7266 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7267 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7268 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7269 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7270 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7271 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7272 | |
| 7273 | std::string response_data; |
| 7274 | rv = ReadTransaction(&trans, &response_data); |
| 7275 | EXPECT_THAT(rv, IsOk()); |
| 7276 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7277 | |
| 7278 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7279 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7280 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7281 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7282 | } |
| 7283 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7284 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7285 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7286 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7287 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7288 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7289 | request.traffic_annotation = |
| 7290 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7291 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7292 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7293 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7294 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7295 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7296 | // Generate the NTLM messages based on known test data. |
| 7297 | std::string negotiate_msg; |
| 7298 | std::string challenge_msg; |
| 7299 | std::string authenticate_msg; |
| 7300 | base::Base64Encode( |
| 7301 | base::StringPiece( |
| 7302 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7303 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7304 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7305 | base::Base64Encode( |
| 7306 | base::StringPiece( |
| 7307 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7308 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7309 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7310 | base::Base64Encode( |
| 7311 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7312 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7313 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7314 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7315 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7316 | &authenticate_msg); |
| 7317 | |
| 7318 | // The authenticate message when |kWrongPassword| is sent. |
| 7319 | std::string wrong_password_authenticate_msg( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7320 | "TlRMTVNTUAADAAAAGAAYAFgAAACKAIoAcAAAAAwADAD6AAAACAAIAAYBAAAQABAADgEAAAAA" |
| 7321 | "AABYAAAAA4IIAAAAAAAAAAAAAPknEYqtJQtusopDRSfYzAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 7322 | "AAAAAOtVz38osnFdRRggUQHUJ3EBAQAAAAAAAIALyP0A1NIBqqqqqqqqqqoAAAAAAgAMAEQA" |
| 7323 | "bwBtAGEAaQBuAAEADABTAGUAcgB2AGUAcgAGAAQAAgAAAAoAEAAAAAAAAAAAAAAAAAAAAAAA" |
| 7324 | "CQAWAEgAVABUAFAALwBzAGUAcgB2AGUAcgAAAAAAAAAAAEQAbwBtAGEAaQBuAFUAcwBlAHIA" |
| 7325 | "QwBPAE0AUABVAFQARQBSAA=="); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7326 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7327 | // Sanity check that it's the same length as the correct authenticate message |
| 7328 | // and that it's different. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7329 | ASSERT_EQ(authenticate_msg.length(), |
| 7330 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7331 | ASSERT_NE(authenticate_msg, wrong_password_authenticate_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7332 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7333 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7334 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7335 | "Host: server\r\n" |
| 7336 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7337 | }; |
| 7338 | |
| 7339 | MockRead data_reads1[] = { |
| 7340 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7341 | // Negotiate and NTLM are often requested together. However, we only want |
| 7342 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7343 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7344 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7345 | MockRead("Connection: close\r\n"), |
| 7346 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7347 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7348 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7349 | }; |
| 7350 | |
| 7351 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7352 | // After restarting with a null identity, this is the |
| 7353 | // request we should be issuing -- the final header line contains a Type |
| 7354 | // 1 message. |
| 7355 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7356 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7357 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7358 | "Authorization: NTLM "), |
| 7359 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7360 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7361 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7362 | // (using incorrect credentials). The second request continues on the |
| 7363 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7364 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7365 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7366 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7367 | "Authorization: NTLM "), |
| 7368 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7369 | }; |
| 7370 | |
| 7371 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7372 | // The origin server responds with a Type 2 message. |
| 7373 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7374 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7375 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 7376 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7377 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7378 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7379 | // Wrong password. |
| 7380 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7381 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 7382 | MockRead("Content-Length: 42\r\n"), |
| 7383 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7384 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7385 | }; |
| 7386 | |
| 7387 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7388 | // After restarting with a null identity, this is the |
| 7389 | // request we should be issuing -- the final header line contains a Type |
| 7390 | // 1 message. |
| 7391 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7392 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7393 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7394 | "Authorization: NTLM "), |
| 7395 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7396 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7397 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7398 | // (the credentials for the origin server). The second request continues |
| 7399 | // on the same connection. |
| 7400 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7401 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7402 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7403 | "Authorization: NTLM "), |
| 7404 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7405 | }; |
| 7406 | |
| 7407 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7408 | // The origin server responds with a Type 2 message. |
| 7409 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7410 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7411 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7412 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7413 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7414 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7415 | // Lastly we get the desired content. |
| 7416 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7417 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7418 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7419 | }; |
| 7420 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7421 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7422 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7423 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7424 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7425 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7426 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7427 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7428 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7429 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7430 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7431 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7432 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 7433 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 7434 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7435 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7436 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7437 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7438 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7439 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7440 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7441 | |
| 7442 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7443 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7444 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7445 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7446 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7447 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7448 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7449 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7450 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7451 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7452 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7453 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7454 | rv = trans.RestartWithAuth( |
| 7455 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 7456 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7457 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7458 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7459 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7460 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7461 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7462 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7463 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7464 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7465 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7466 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7467 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7468 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7469 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7470 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7471 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7472 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7473 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7474 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7475 | |
| 7476 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7477 | rv = trans.RestartWithAuth( |
| 7478 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7479 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7480 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7481 | |
| 7482 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7483 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7484 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7485 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7486 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7487 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7488 | |
| 7489 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7490 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7491 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7492 | |
| 7493 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7494 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7495 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7496 | response = trans.GetResponseInfo(); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7497 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7498 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7499 | |
| 7500 | std::string response_data; |
| 7501 | rv = ReadTransaction(&trans, &response_data); |
| 7502 | EXPECT_THAT(rv, IsOk()); |
| 7503 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7504 | |
| 7505 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7506 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7507 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7508 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 7509 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 7510 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7511 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7512 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7513 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 7514 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7515 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7516 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7517 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7518 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7519 | const char* kUrl = "https://server/kids/login.aspx"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7520 | |
| 7521 | HttpRequestInfo request; |
| 7522 | request.method = "GET"; |
| 7523 | request.url = GURL(kUrl); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7524 | request.traffic_annotation = |
| 7525 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7526 | |
| 7527 | // First request without credentials. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7528 | spdy::SpdyHeaderBlock request_headers0( |
| 7529 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 7530 | spdy::SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7531 | 1, std::move(request_headers0), LOWEST, true)); |
| 7532 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7533 | spdy::SpdyHeaderBlock response_headers0; |
| 7534 | response_headers0[spdy::kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7535 | response_headers0["www-authenticate"] = "NTLM"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7536 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7537 | 1, std::move(response_headers0), true)); |
| 7538 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7539 | // Stream 1 is closed. |
| 7540 | spdy_util_.UpdateWithStreamDestruction(1); |
| 7541 | |
| 7542 | // Generate the NTLM messages based on known test data. |
| 7543 | std::string negotiate_msg; |
| 7544 | std::string challenge_msg; |
| 7545 | std::string authenticate_msg; |
| 7546 | base::Base64Encode( |
| 7547 | base::StringPiece( |
| 7548 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7549 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7550 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7551 | base::Base64Encode( |
| 7552 | base::StringPiece( |
| 7553 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7554 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7555 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7556 | base::Base64Encode( |
| 7557 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7558 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7559 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7560 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7561 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7562 | &authenticate_msg); |
| 7563 | |
| 7564 | // Retry with authorization header. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7565 | spdy::SpdyHeaderBlock request_headers1( |
| 7566 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7567 | request_headers1["authorization"] = std::string("NTLM ") + negotiate_msg; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7568 | spdy::SpdySerializedFrame request1(spdy_util_.ConstructSpdyHeaders( |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7569 | 3, std::move(request_headers1), LOWEST, true)); |
| 7570 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7571 | spdy::SpdySerializedFrame rst( |
| 7572 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_HTTP_1_1_REQUIRED)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7573 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7574 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
| 7575 | MockRead reads0[] = {CreateMockRead(resp, 1), MockRead(ASYNC, 0, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7576 | |
| 7577 | // Retry yet again using HTTP/1.1. |
| 7578 | MockWrite writes1[] = { |
| 7579 | // After restarting with a null identity, this is the |
| 7580 | // request we should be issuing -- the final header line contains a Type |
| 7581 | // 1 message. |
| 7582 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7583 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7584 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7585 | "Authorization: NTLM "), |
| 7586 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7587 | |
| 7588 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7589 | // (the credentials for the origin server). The second request continues |
| 7590 | // on the same connection. |
| 7591 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7592 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7593 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7594 | "Authorization: NTLM "), |
| 7595 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7596 | }; |
| 7597 | |
| 7598 | MockRead reads1[] = { |
| 7599 | // The origin server responds with a Type 2 message. |
| 7600 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7601 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7602 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7603 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7604 | MockRead("You are not authorized to view this page\r\n"), |
| 7605 | |
| 7606 | // Lastly we get the desired content. |
| 7607 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7608 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7609 | 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] | 7610 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7611 | SequencedSocketData data0(reads0, writes0); |
| 7612 | StaticSocketDataProvider data1(reads1, writes1); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7613 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 7614 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7615 | |
| 7616 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 7617 | ssl0.next_proto = kProtoHTTP2; |
| 7618 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7619 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 7620 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7621 | |
| 7622 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7623 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7624 | |
| 7625 | TestCompletionCallback callback1; |
| 7626 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 7627 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7628 | |
| 7629 | rv = callback1.WaitForResult(); |
| 7630 | EXPECT_THAT(rv, IsOk()); |
| 7631 | |
| 7632 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7633 | |
| 7634 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7635 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7636 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7637 | |
| 7638 | TestCompletionCallback callback2; |
| 7639 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7640 | rv = trans.RestartWithAuth( |
| 7641 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7642 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7643 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7644 | |
| 7645 | rv = callback2.WaitForResult(); |
| 7646 | EXPECT_THAT(rv, IsOk()); |
| 7647 | |
| 7648 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7649 | |
| 7650 | response = trans.GetResponseInfo(); |
| 7651 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7652 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7653 | |
| 7654 | TestCompletionCallback callback3; |
| 7655 | |
| 7656 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 7657 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7658 | |
| 7659 | rv = callback3.WaitForResult(); |
| 7660 | EXPECT_THAT(rv, IsOk()); |
| 7661 | |
| 7662 | response = trans.GetResponseInfo(); |
| 7663 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7664 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7665 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7666 | |
| 7667 | std::string response_data; |
| 7668 | rv = ReadTransaction(&trans, &response_data); |
| 7669 | EXPECT_THAT(rv, IsOk()); |
| 7670 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7671 | |
| 7672 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 7673 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 7674 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7675 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7676 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7677 | |
| 7678 | // Test that, if we have an NTLM proxy and the origin resets the connection, we |
| 7679 | // do no retry forever checking for TLS version interference. This is a |
| 7680 | // regression test for https://crbug.com/823387. |
| 7681 | TEST_F(HttpNetworkTransactionTest, NTLMProxyTLSHandshakeReset) { |
| 7682 | // The NTLM test data expects the proxy to be named 'server'. The origin is |
| 7683 | // https://origin/. |
| 7684 | session_deps_.proxy_resolution_service = |
| 7685 | ProxyResolutionService::CreateFixedFromPacResult( |
| 7686 | "PROXY server", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7687 | |
| 7688 | SSLConfig config; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7689 | session_deps_.ssl_config_service = |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 7690 | std::make_unique<TestSSLConfigService>(config); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7691 | |
| 7692 | HttpRequestInfo request; |
| 7693 | request.method = "GET"; |
| 7694 | request.url = GURL("https://origin/"); |
| 7695 | request.traffic_annotation = |
| 7696 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7697 | |
| 7698 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7699 | // to other auth schemes. |
| 7700 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 7701 | |
| 7702 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7703 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
| 7704 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7705 | |
| 7706 | // Generate the NTLM messages based on known test data. |
| 7707 | std::string negotiate_msg; |
| 7708 | std::string challenge_msg; |
| 7709 | std::string authenticate_msg; |
| 7710 | base::Base64Encode( |
| 7711 | base::StringPiece( |
| 7712 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7713 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7714 | &negotiate_msg); |
| 7715 | base::Base64Encode( |
| 7716 | base::StringPiece( |
| 7717 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7718 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7719 | &challenge_msg); |
| 7720 | base::Base64Encode( |
| 7721 | base::StringPiece( |
| 7722 | reinterpret_cast<const char*>( |
| 7723 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7724 | base::size( |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7725 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
| 7726 | &authenticate_msg); |
| 7727 | |
| 7728 | MockWrite data_writes[] = { |
| 7729 | // The initial CONNECT request. |
| 7730 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7731 | "Host: origin:443\r\n" |
| 7732 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7733 | |
| 7734 | // After restarting with an identity. |
| 7735 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7736 | "Host: origin:443\r\n" |
| 7737 | "Proxy-Connection: keep-alive\r\n" |
| 7738 | "Proxy-Authorization: NTLM "), |
| 7739 | MockWrite(negotiate_msg.c_str()), |
| 7740 | // End headers. |
| 7741 | MockWrite("\r\n\r\n"), |
| 7742 | |
| 7743 | // The second restart. |
| 7744 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7745 | "Host: origin:443\r\n" |
| 7746 | "Proxy-Connection: keep-alive\r\n" |
| 7747 | "Proxy-Authorization: NTLM "), |
| 7748 | MockWrite(authenticate_msg.c_str()), |
| 7749 | // End headers. |
| 7750 | MockWrite("\r\n\r\n"), |
| 7751 | }; |
| 7752 | |
| 7753 | MockRead data_reads[] = { |
| 7754 | // The initial NTLM response. |
| 7755 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 7756 | "Content-Length: 0\r\n" |
| 7757 | "Proxy-Authenticate: NTLM\r\n\r\n"), |
| 7758 | |
| 7759 | // The NTLM challenge message. |
| 7760 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 7761 | "Content-Length: 0\r\n" |
| 7762 | "Proxy-Authenticate: NTLM "), |
| 7763 | MockRead(challenge_msg.c_str()), |
| 7764 | // End headers. |
| 7765 | MockRead("\r\n\r\n"), |
| 7766 | |
| 7767 | // Finally the tunnel is established. |
| 7768 | MockRead("HTTP/1.1 200 Connected\r\n\r\n"), |
| 7769 | }; |
| 7770 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7771 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7772 | SSLSocketDataProvider data_ssl(ASYNC, ERR_CONNECTION_RESET); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7773 | StaticSocketDataProvider data2(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7774 | SSLSocketDataProvider data_ssl2(ASYNC, ERR_CONNECTION_RESET); |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 7775 | data_ssl2.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7776 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7777 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl); |
| 7778 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7779 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl2); |
| 7780 | |
| 7781 | // Start the transaction. The proxy responds with an NTLM authentication |
| 7782 | // request. |
| 7783 | TestCompletionCallback callback; |
| 7784 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7785 | int rv = callback.GetResult( |
| 7786 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 7787 | |
| 7788 | EXPECT_THAT(rv, IsOk()); |
| 7789 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7790 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7791 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7792 | EXPECT_TRUE(CheckNTLMProxyAuth(response->auth_challenge)); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7793 | |
| 7794 | // Configure credentials. The proxy responds with the challenge message. |
| 7795 | rv = callback.GetResult(trans.RestartWithAuth( |
| 7796 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7797 | callback.callback())); |
| 7798 | EXPECT_THAT(rv, IsOk()); |
| 7799 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7800 | response = trans.GetResponseInfo(); |
| 7801 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7802 | EXPECT_FALSE(response->auth_challenge.has_value()); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7803 | |
| 7804 | // Restart once more. The tunnel will be established and the the SSL handshake |
| 7805 | // will reset. The TLS 1.3 version interference probe will then kick in and |
| 7806 | // restart the process. The proxy responds with another NTLM authentiation |
| 7807 | // request, but we don't need to provide credentials as the cached ones work/ |
| 7808 | rv = callback.GetResult( |
| 7809 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7810 | EXPECT_THAT(rv, IsOk()); |
| 7811 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7812 | response = trans.GetResponseInfo(); |
| 7813 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7814 | EXPECT_FALSE(response->auth_challenge.has_value()); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7815 | |
| 7816 | // The proxy responds with the NTLM challenge message. |
| 7817 | rv = callback.GetResult( |
| 7818 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7819 | EXPECT_THAT(rv, IsOk()); |
| 7820 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7821 | response = trans.GetResponseInfo(); |
| 7822 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7823 | EXPECT_FALSE(response->auth_challenge.has_value()); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7824 | |
| 7825 | // Send the NTLM authenticate message. The tunnel is established and the |
| 7826 | // handshake resets again. We should not retry again. |
| 7827 | rv = callback.GetResult( |
| 7828 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7829 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
| 7830 | } |
| 7831 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7832 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7833 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7834 | // Test reading a server response which has only headers, and no body. |
| 7835 | // After some maximum number of bytes is consumed, the transaction should |
| 7836 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7837 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7838 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7839 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7840 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7841 | request.traffic_annotation = |
| 7842 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7843 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7844 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7845 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7846 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7847 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 7848 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7849 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7850 | |
| 7851 | MockRead data_reads[] = { |
| 7852 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7853 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7854 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7855 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7856 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7857 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7858 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7859 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7860 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7861 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7862 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7863 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7864 | |
| 7865 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7866 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7867 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7868 | |
| 7869 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 7870 | // establish tunnel. |
| 7871 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7872 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7873 | HttpRequestInfo request; |
| 7874 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7875 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7876 | request.traffic_annotation = |
| 7877 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7878 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7879 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 7880 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 7881 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 7882 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7883 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7884 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7885 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7886 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7887 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7888 | // Since we have proxy, should try to establish tunnel. |
| 7889 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7890 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7891 | "Host: www.example.org:443\r\n" |
| 7892 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7893 | }; |
| 7894 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7895 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7896 | // connection. Usually a proxy would return 501 (not implemented), |
| 7897 | // or 200 (tunnel established). |
| 7898 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 7899 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7900 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7901 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7902 | }; |
| 7903 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7904 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7905 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7906 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7907 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7908 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7909 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7910 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7911 | |
| 7912 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7913 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7914 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7915 | // Empty the current queue. This is necessary because idle sockets are |
| 7916 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7917 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7918 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7919 | // We now check to make sure the TCPClientSocket was not added back to |
| 7920 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7921 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7922 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7923 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7924 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7925 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7926 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7927 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7928 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7929 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7930 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7931 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7932 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7933 | request.traffic_annotation = |
| 7934 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7935 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7936 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7937 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7938 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7939 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7940 | MockRead data_reads[] = { |
| 7941 | // A part of the response body is received with the response headers. |
| 7942 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7943 | // The rest of the response body is received in two parts. |
| 7944 | MockRead("lo"), |
| 7945 | MockRead(" world"), |
| 7946 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7947 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7948 | }; |
| 7949 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7950 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7951 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7952 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7953 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7954 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7955 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7956 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7957 | |
| 7958 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7959 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7960 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7961 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7962 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7963 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7964 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7965 | std::string status_line = response->headers->GetStatusLine(); |
| 7966 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7967 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7968 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7969 | |
| 7970 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7971 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7972 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7973 | EXPECT_EQ("hello world", response_data); |
| 7974 | |
| 7975 | // Empty the current queue. This is necessary because idle sockets are |
| 7976 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7977 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7978 | |
| 7979 | // 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] | 7980 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7981 | } |
| 7982 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7983 | // Make sure that we recycle a SSL socket after reading all of the response |
| 7984 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7985 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7986 | HttpRequestInfo request; |
| 7987 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7988 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7989 | request.traffic_annotation = |
| 7990 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7991 | |
| 7992 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7993 | MockWrite( |
| 7994 | "GET / HTTP/1.1\r\n" |
| 7995 | "Host: www.example.org\r\n" |
| 7996 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7997 | }; |
| 7998 | |
| 7999 | MockRead data_reads[] = { |
| 8000 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8001 | MockRead("Content-Length: 11\r\n\r\n"), |
| 8002 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8003 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8004 | }; |
| 8005 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8006 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8007 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8008 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8009 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8010 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8011 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8012 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8013 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8014 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8015 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8016 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8017 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8018 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8019 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8020 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8021 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8022 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8023 | ASSERT_TRUE(response); |
| 8024 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8025 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8026 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8027 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8028 | |
| 8029 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8030 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8031 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8032 | EXPECT_EQ("hello world", response_data); |
| 8033 | |
| 8034 | // Empty the current queue. This is necessary because idle sockets are |
| 8035 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8036 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8037 | |
| 8038 | // 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] | 8039 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8040 | } |
| 8041 | |
| 8042 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 8043 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8044 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8045 | HttpRequestInfo request; |
| 8046 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8047 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8048 | request.traffic_annotation = |
| 8049 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8050 | |
| 8051 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8052 | MockWrite( |
| 8053 | "GET / HTTP/1.1\r\n" |
| 8054 | "Host: www.example.org\r\n" |
| 8055 | "Connection: keep-alive\r\n\r\n"), |
| 8056 | MockWrite( |
| 8057 | "GET / HTTP/1.1\r\n" |
| 8058 | "Host: www.example.org\r\n" |
| 8059 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8060 | }; |
| 8061 | |
| 8062 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 8063 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8064 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8065 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8066 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8067 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8068 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8069 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8070 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8071 | StaticSocketDataProvider data(data_reads, data_writes); |
| 8072 | StaticSocketDataProvider data2(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8073 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8074 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8075 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8076 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8077 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8078 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8079 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8080 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8081 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8082 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8083 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8084 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8085 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8086 | |
| 8087 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8088 | ASSERT_TRUE(response); |
| 8089 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8090 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8091 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8092 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8093 | |
| 8094 | std::string response_data; |
| 8095 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8096 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8097 | EXPECT_EQ("hello world", response_data); |
| 8098 | |
| 8099 | // Empty the current queue. This is necessary because idle sockets are |
| 8100 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8101 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8102 | |
| 8103 | // 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] | 8104 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8105 | |
| 8106 | // Now start the second transaction, which should reuse the previous socket. |
| 8107 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8108 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8109 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8110 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8111 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8112 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8113 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8114 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8115 | |
| 8116 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8117 | ASSERT_TRUE(response); |
| 8118 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8119 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8120 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8121 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8122 | |
| 8123 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8124 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8125 | EXPECT_EQ("hello world", response_data); |
| 8126 | |
| 8127 | // Empty the current queue. This is necessary because idle sockets are |
| 8128 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8129 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8130 | |
| 8131 | // 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] | 8132 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8133 | } |
| 8134 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8135 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8136 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8137 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8138 | HttpRequestInfo request; |
| 8139 | request.method = "GET"; |
| 8140 | request.url = GURL("http://www.example.org/"); |
| 8141 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8142 | request.traffic_annotation = |
| 8143 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8144 | |
| 8145 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8146 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8147 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8148 | |
| 8149 | MockRead data_reads[] = { |
| 8150 | // A part of the response body is received with the response headers. |
| 8151 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8152 | // The rest of the response body is received in two parts. |
| 8153 | MockRead("lo"), MockRead(" world"), |
| 8154 | MockRead("junk"), // Should not be read!! |
| 8155 | MockRead(SYNCHRONOUS, OK), |
| 8156 | }; |
| 8157 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8158 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8159 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8160 | |
| 8161 | TestCompletionCallback callback; |
| 8162 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8163 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8164 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8165 | |
| 8166 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8167 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8168 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8169 | ASSERT_TRUE(response); |
| 8170 | EXPECT_TRUE(response->headers); |
| 8171 | std::string status_line = response->headers->GetStatusLine(); |
| 8172 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8173 | |
| 8174 | // Make memory critical notification and ensure the transaction still has been |
| 8175 | // operating right. |
| 8176 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8177 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8178 | base::RunLoop().RunUntilIdle(); |
| 8179 | |
| 8180 | // Socket should not be flushed as long as it is not idle. |
| 8181 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8182 | |
| 8183 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8184 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8185 | EXPECT_THAT(rv, IsOk()); |
| 8186 | EXPECT_EQ("hello world", response_data); |
| 8187 | |
| 8188 | // Empty the current queue. This is necessary because idle sockets are |
| 8189 | // added to the connection pool asynchronously with a PostTask. |
| 8190 | base::RunLoop().RunUntilIdle(); |
| 8191 | |
| 8192 | // We now check to make sure the socket was added back to the pool. |
| 8193 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8194 | |
| 8195 | // Idle sockets should be flushed now. |
| 8196 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8197 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8198 | base::RunLoop().RunUntilIdle(); |
| 8199 | |
| 8200 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8201 | } |
| 8202 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8203 | // Disable idle socket closing on memory pressure. |
| 8204 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8205 | // low memory notification and ensure the socket pool is NOT flushed. |
| 8206 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 8207 | HttpRequestInfo request; |
| 8208 | request.method = "GET"; |
| 8209 | request.url = GURL("http://www.example.org/"); |
| 8210 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8211 | request.traffic_annotation = |
| 8212 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8213 | |
| 8214 | // Disable idle socket closing on memory pressure. |
| 8215 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 8216 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8217 | |
| 8218 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 8219 | |
| 8220 | MockRead data_reads[] = { |
| 8221 | // A part of the response body is received with the response headers. |
| 8222 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8223 | // The rest of the response body is received in two parts. |
| 8224 | MockRead("lo"), MockRead(" world"), |
| 8225 | MockRead("junk"), // Should not be read!! |
| 8226 | MockRead(SYNCHRONOUS, OK), |
| 8227 | }; |
| 8228 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8229 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8230 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8231 | |
| 8232 | TestCompletionCallback callback; |
| 8233 | |
| 8234 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 8235 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8236 | |
| 8237 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8238 | |
| 8239 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 8240 | ASSERT_TRUE(response); |
| 8241 | EXPECT_TRUE(response->headers); |
| 8242 | std::string status_line = response->headers->GetStatusLine(); |
| 8243 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8244 | |
| 8245 | // Make memory critical notification and ensure the transaction still has been |
| 8246 | // operating right. |
| 8247 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8248 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8249 | base::RunLoop().RunUntilIdle(); |
| 8250 | |
| 8251 | // Socket should not be flushed as long as it is not idle. |
| 8252 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8253 | |
| 8254 | std::string response_data; |
| 8255 | rv = ReadTransaction(&trans, &response_data); |
| 8256 | EXPECT_THAT(rv, IsOk()); |
| 8257 | EXPECT_EQ("hello world", response_data); |
| 8258 | |
| 8259 | // Empty the current queue. This is necessary because idle sockets are |
| 8260 | // added to the connection pool asynchronously with a PostTask. |
| 8261 | base::RunLoop().RunUntilIdle(); |
| 8262 | |
| 8263 | // We now check to make sure the socket was added back to the pool. |
| 8264 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8265 | |
| 8266 | // Idle sockets should NOT be flushed on moderate memory pressure. |
| 8267 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8268 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 8269 | base::RunLoop().RunUntilIdle(); |
| 8270 | |
| 8271 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8272 | |
| 8273 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 8274 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8275 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8276 | base::RunLoop().RunUntilIdle(); |
| 8277 | |
| 8278 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8279 | } |
| 8280 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8281 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 8282 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8283 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8284 | HttpRequestInfo request; |
| 8285 | request.method = "GET"; |
| 8286 | request.url = GURL("https://www.example.org/"); |
| 8287 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8288 | request.traffic_annotation = |
| 8289 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8290 | |
| 8291 | MockWrite data_writes[] = { |
| 8292 | MockWrite("GET / HTTP/1.1\r\n" |
| 8293 | "Host: www.example.org\r\n" |
| 8294 | "Connection: keep-alive\r\n\r\n"), |
| 8295 | }; |
| 8296 | |
| 8297 | MockRead data_reads[] = { |
| 8298 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8299 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 8300 | |
| 8301 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8302 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8303 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8304 | StaticSocketDataProvider data(data_reads, data_writes); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8305 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8306 | |
| 8307 | TestCompletionCallback callback; |
| 8308 | |
| 8309 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8310 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8311 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8312 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8313 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8314 | |
| 8315 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8316 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8317 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8318 | ASSERT_TRUE(response); |
| 8319 | ASSERT_TRUE(response->headers); |
| 8320 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8321 | |
| 8322 | // Make memory critical notification and ensure the transaction still has been |
| 8323 | // operating right. |
| 8324 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8325 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8326 | base::RunLoop().RunUntilIdle(); |
| 8327 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8328 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8329 | |
| 8330 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8331 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8332 | EXPECT_THAT(rv, IsOk()); |
| 8333 | EXPECT_EQ("hello world", response_data); |
| 8334 | |
| 8335 | // Empty the current queue. This is necessary because idle sockets are |
| 8336 | // added to the connection pool asynchronously with a PostTask. |
| 8337 | base::RunLoop().RunUntilIdle(); |
| 8338 | |
| 8339 | // 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] | 8340 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8341 | |
| 8342 | // Make memory notification once again and ensure idle socket is closed. |
| 8343 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8344 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8345 | base::RunLoop().RunUntilIdle(); |
| 8346 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8347 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8348 | } |
| 8349 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8350 | // Make sure that we recycle a socket after a zero-length response. |
| 8351 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8352 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8353 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8354 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8355 | request.url = GURL( |
| 8356 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 8357 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 8358 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 8359 | "rt=prt.2642,ol.2649,xjs.2951"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8360 | request.traffic_annotation = |
| 8361 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8362 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8363 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8364 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8365 | MockRead data_reads[] = { |
| 8366 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 8367 | "Content-Length: 0\r\n" |
| 8368 | "Content-Type: text/html\r\n\r\n"), |
| 8369 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8370 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8371 | }; |
| 8372 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8373 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8374 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8375 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8376 | // Transaction must be created after the MockReads, so it's destroyed before |
| 8377 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8378 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8379 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8380 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8381 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8382 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8383 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8384 | |
| 8385 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8386 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8387 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8388 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8389 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8390 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8391 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8392 | std::string status_line = response->headers->GetStatusLine(); |
| 8393 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 8394 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8395 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8396 | |
| 8397 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8398 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8399 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8400 | EXPECT_EQ("", response_data); |
| 8401 | |
| 8402 | // Empty the current queue. This is necessary because idle sockets are |
| 8403 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8404 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8405 | |
| 8406 | // 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] | 8407 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8408 | } |
| 8409 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8410 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8411 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8412 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8413 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8414 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8415 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8416 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8417 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 8418 | // after use. |
| 8419 | request[0].method = "GET"; |
| 8420 | request[0].url = GURL("http://www.google.com/"); |
| 8421 | request[0].load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8422 | request[0].traffic_annotation = |
| 8423 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8424 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 8425 | // transaction 1. The first attempts fails when writing the POST data. |
| 8426 | // This causes the transaction to retry with a new socket. The second |
| 8427 | // attempt succeeds. |
| 8428 | request[1].method = "POST"; |
| 8429 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8430 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8431 | request[1].load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8432 | request[1].traffic_annotation = |
| 8433 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8434 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8435 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8436 | |
| 8437 | // The first socket is used for transaction 1 and the first attempt of |
| 8438 | // transaction 2. |
| 8439 | |
| 8440 | // The response of transaction 1. |
| 8441 | MockRead data_reads1[] = { |
| 8442 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 8443 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8444 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8445 | }; |
| 8446 | // The mock write results of transaction 1 and the first attempt of |
| 8447 | // transaction 2. |
| 8448 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8449 | MockWrite(SYNCHRONOUS, 64), // GET |
| 8450 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8451 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8452 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8453 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8454 | |
| 8455 | // The second socket is used for the second attempt of transaction 2. |
| 8456 | |
| 8457 | // The response of transaction 2. |
| 8458 | MockRead data_reads2[] = { |
| 8459 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 8460 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8461 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8462 | }; |
| 8463 | // The mock write results of the second attempt of transaction 2. |
| 8464 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8465 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8466 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8467 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8468 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8469 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8470 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8471 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8472 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8473 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8474 | "hello world", "welcome" |
| 8475 | }; |
| 8476 | |
| 8477 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8478 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8479 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8480 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8481 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8482 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8483 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8484 | |
| 8485 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8486 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8487 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8488 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8489 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8490 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8491 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8492 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8493 | |
| 8494 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8495 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8496 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8497 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 8498 | } |
| 8499 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8500 | |
| 8501 | // Test the request-challenge-retry sequence for basic auth when there is |
| 8502 | // 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] | 8503 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8504 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8505 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8506 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8507 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 8508 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8509 | request.traffic_annotation = |
| 8510 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8511 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8512 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8513 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8514 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8515 | // The password contains an escaped character -- for this test to pass it |
| 8516 | // will need to be unescaped by HttpNetworkTransaction. |
| 8517 | EXPECT_EQ("b%40r", request.url.password()); |
| 8518 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8519 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8520 | MockWrite( |
| 8521 | "GET / HTTP/1.1\r\n" |
| 8522 | "Host: www.example.org\r\n" |
| 8523 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8524 | }; |
| 8525 | |
| 8526 | MockRead data_reads1[] = { |
| 8527 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8528 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8529 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8530 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8531 | }; |
| 8532 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8533 | // After the challenge above, the transaction will be restarted using the |
| 8534 | // identity from the url (foo, b@r) to answer the challenge. |
| 8535 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8536 | MockWrite( |
| 8537 | "GET / HTTP/1.1\r\n" |
| 8538 | "Host: www.example.org\r\n" |
| 8539 | "Connection: keep-alive\r\n" |
| 8540 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8541 | }; |
| 8542 | |
| 8543 | MockRead data_reads2[] = { |
| 8544 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8545 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8546 | MockRead(SYNCHRONOUS, OK), |
| 8547 | }; |
| 8548 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8549 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8550 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8551 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8552 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8553 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8554 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8555 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8556 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8557 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8558 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8559 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8560 | |
| 8561 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8562 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8563 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8564 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8565 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8566 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8567 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8568 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8569 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8570 | |
| 8571 | // There is no challenge info, since the identity in URL worked. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8572 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8573 | |
| 8574 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8575 | |
| 8576 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8577 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8578 | } |
| 8579 | |
| 8580 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 8581 | // incorrect identity in the URL. The identity from the URL should be used only |
| 8582 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8583 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8584 | HttpRequestInfo request; |
| 8585 | request.method = "GET"; |
| 8586 | // Note: the URL has a username:password in it. The password "baz" is |
| 8587 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8588 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8589 | |
| 8590 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8591 | request.traffic_annotation = |
| 8592 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8593 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8594 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8595 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8596 | |
| 8597 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8598 | MockWrite( |
| 8599 | "GET / HTTP/1.1\r\n" |
| 8600 | "Host: www.example.org\r\n" |
| 8601 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8602 | }; |
| 8603 | |
| 8604 | MockRead data_reads1[] = { |
| 8605 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8606 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8607 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8608 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8609 | }; |
| 8610 | |
| 8611 | // After the challenge above, the transaction will be restarted using the |
| 8612 | // identity from the url (foo, baz) to answer the challenge. |
| 8613 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8614 | MockWrite( |
| 8615 | "GET / HTTP/1.1\r\n" |
| 8616 | "Host: www.example.org\r\n" |
| 8617 | "Connection: keep-alive\r\n" |
| 8618 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8619 | }; |
| 8620 | |
| 8621 | MockRead data_reads2[] = { |
| 8622 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8623 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8624 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8625 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8626 | }; |
| 8627 | |
| 8628 | // After the challenge above, the transaction will be restarted using the |
| 8629 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 8630 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8631 | MockWrite( |
| 8632 | "GET / HTTP/1.1\r\n" |
| 8633 | "Host: www.example.org\r\n" |
| 8634 | "Connection: keep-alive\r\n" |
| 8635 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8636 | }; |
| 8637 | |
| 8638 | MockRead data_reads3[] = { |
| 8639 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8640 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8641 | MockRead(SYNCHRONOUS, OK), |
| 8642 | }; |
| 8643 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8644 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8645 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 8646 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8647 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8648 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8649 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8650 | |
| 8651 | TestCompletionCallback callback1; |
| 8652 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8653 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8654 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8655 | |
| 8656 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8657 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8658 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8659 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8660 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8661 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8662 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8663 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8664 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8665 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8666 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8667 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8668 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8669 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8670 | |
| 8671 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8672 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8673 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8674 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8675 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8676 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8677 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8678 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8679 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8680 | |
| 8681 | // There is no challenge info, since the identity worked. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8682 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8683 | |
| 8684 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8685 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8686 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8687 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8688 | } |
| 8689 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8690 | |
| 8691 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 8692 | // correct identity in the URL, but its use is being suppressed. The identity |
| 8693 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8694 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8695 | HttpRequestInfo request; |
| 8696 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8697 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8698 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8699 | request.traffic_annotation = |
| 8700 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8701 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8702 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8703 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8704 | |
| 8705 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8706 | MockWrite( |
| 8707 | "GET / HTTP/1.1\r\n" |
| 8708 | "Host: www.example.org\r\n" |
| 8709 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8710 | }; |
| 8711 | |
| 8712 | MockRead data_reads1[] = { |
| 8713 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8714 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8715 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8716 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8717 | }; |
| 8718 | |
| 8719 | // After the challenge above, the transaction will be restarted using the |
| 8720 | // identity supplied by the user, not the one in the URL, to answer the |
| 8721 | // challenge. |
| 8722 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8723 | MockWrite( |
| 8724 | "GET / HTTP/1.1\r\n" |
| 8725 | "Host: www.example.org\r\n" |
| 8726 | "Connection: keep-alive\r\n" |
| 8727 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8728 | }; |
| 8729 | |
| 8730 | MockRead data_reads3[] = { |
| 8731 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8732 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8733 | MockRead(SYNCHRONOUS, OK), |
| 8734 | }; |
| 8735 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8736 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8737 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8738 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8739 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 8740 | |
| 8741 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8742 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8743 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8744 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8745 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8746 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8747 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8748 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8749 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8750 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8751 | |
| 8752 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8753 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8754 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8755 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8756 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8757 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8758 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8759 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8760 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8761 | |
| 8762 | // There is no challenge info, since the identity worked. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8763 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8764 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8765 | |
| 8766 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8767 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8768 | } |
| 8769 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8770 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8771 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8772 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8773 | |
| 8774 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 8775 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8776 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8777 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8778 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8779 | request.traffic_annotation = |
| 8780 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8781 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8782 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8783 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8784 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8785 | MockWrite( |
| 8786 | "GET /x/y/z HTTP/1.1\r\n" |
| 8787 | "Host: www.example.org\r\n" |
| 8788 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8789 | }; |
| 8790 | |
| 8791 | MockRead data_reads1[] = { |
| 8792 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8793 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8794 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8795 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8796 | }; |
| 8797 | |
| 8798 | // Resend with authorization (username=foo, password=bar) |
| 8799 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8800 | MockWrite( |
| 8801 | "GET /x/y/z HTTP/1.1\r\n" |
| 8802 | "Host: www.example.org\r\n" |
| 8803 | "Connection: keep-alive\r\n" |
| 8804 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8805 | }; |
| 8806 | |
| 8807 | // Sever accepts the authorization. |
| 8808 | MockRead data_reads2[] = { |
| 8809 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8810 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8811 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8812 | }; |
| 8813 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8814 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8815 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8816 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8817 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8818 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8819 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8820 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8821 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8822 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8823 | |
| 8824 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8825 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8826 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8827 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8828 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8829 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8830 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8831 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8832 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8833 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8834 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8835 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8836 | |
| 8837 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8838 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8839 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8840 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8841 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8842 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8843 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8844 | } |
| 8845 | |
| 8846 | // ------------------------------------------------------------------------ |
| 8847 | |
| 8848 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 8849 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8850 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8851 | request.method = "GET"; |
| 8852 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 8853 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8854 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8855 | request.traffic_annotation = |
| 8856 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8857 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8858 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8859 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8860 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8861 | MockWrite( |
| 8862 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8863 | "Host: www.example.org\r\n" |
| 8864 | "Connection: keep-alive\r\n" |
| 8865 | // Send preemptive authorization for MyRealm1 |
| 8866 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8867 | }; |
| 8868 | |
| 8869 | // The server didn't like the preemptive authorization, and |
| 8870 | // challenges us for a different realm (MyRealm2). |
| 8871 | MockRead data_reads1[] = { |
| 8872 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8873 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 8874 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8875 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8876 | }; |
| 8877 | |
| 8878 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 8879 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8880 | MockWrite( |
| 8881 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8882 | "Host: www.example.org\r\n" |
| 8883 | "Connection: keep-alive\r\n" |
| 8884 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8885 | }; |
| 8886 | |
| 8887 | // Sever accepts the authorization. |
| 8888 | MockRead data_reads2[] = { |
| 8889 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8890 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8891 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8892 | }; |
| 8893 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8894 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8895 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8896 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8897 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8898 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8899 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8900 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8901 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8902 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8903 | |
| 8904 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8905 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8906 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8907 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8908 | ASSERT_TRUE(response); |
| 8909 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8910 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8911 | EXPECT_EQ("http://www.example.org", |
| 8912 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8913 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 8914 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8915 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8916 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8917 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8918 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 8919 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8920 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8921 | |
| 8922 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8923 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8924 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8925 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8926 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8927 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8928 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8929 | } |
| 8930 | |
| 8931 | // ------------------------------------------------------------------------ |
| 8932 | |
| 8933 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 8934 | // succeed with preemptive authorization. |
| 8935 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8936 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8937 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8938 | request.url = GURL("http://www.example.org/x/y/z2"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8939 | request.traffic_annotation = |
| 8940 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8941 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8942 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8943 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8944 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8945 | MockWrite( |
| 8946 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 8947 | "Host: www.example.org\r\n" |
| 8948 | "Connection: keep-alive\r\n" |
| 8949 | // The authorization for MyRealm1 gets sent preemptively |
| 8950 | // (since the url is in the same protection space) |
| 8951 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8952 | }; |
| 8953 | |
| 8954 | // Sever accepts the preemptive authorization |
| 8955 | MockRead data_reads1[] = { |
| 8956 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8957 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8958 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8959 | }; |
| 8960 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8961 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8962 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8963 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8964 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8965 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8966 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8967 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8968 | |
| 8969 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8970 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8971 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8972 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8973 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8974 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8975 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8976 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8977 | } |
| 8978 | |
| 8979 | // ------------------------------------------------------------------------ |
| 8980 | |
| 8981 | // Transaction 4: request another URL in MyRealm (however the |
| 8982 | // url is not known to belong to the protection space, so no pre-auth). |
| 8983 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8984 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8985 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8986 | request.url = GURL("http://www.example.org/x/1"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8987 | request.traffic_annotation = |
| 8988 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8989 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8990 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8991 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8992 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8993 | MockWrite( |
| 8994 | "GET /x/1 HTTP/1.1\r\n" |
| 8995 | "Host: www.example.org\r\n" |
| 8996 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8997 | }; |
| 8998 | |
| 8999 | MockRead data_reads1[] = { |
| 9000 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9001 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9002 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9003 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9004 | }; |
| 9005 | |
| 9006 | // Resend with authorization from MyRealm's cache. |
| 9007 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9008 | MockWrite( |
| 9009 | "GET /x/1 HTTP/1.1\r\n" |
| 9010 | "Host: www.example.org\r\n" |
| 9011 | "Connection: keep-alive\r\n" |
| 9012 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9013 | }; |
| 9014 | |
| 9015 | // Sever accepts the authorization. |
| 9016 | MockRead data_reads2[] = { |
| 9017 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9018 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9019 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9020 | }; |
| 9021 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9022 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9023 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9024 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9025 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9026 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9027 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9028 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9029 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9030 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9031 | |
| 9032 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9033 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9034 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9035 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9036 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9037 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9038 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9039 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9040 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9041 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9042 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9043 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9044 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9045 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9046 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9047 | } |
| 9048 | |
| 9049 | // ------------------------------------------------------------------------ |
| 9050 | |
| 9051 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 9052 | // cached identity. Should invalidate and re-prompt. |
| 9053 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9054 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9055 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9056 | request.url = GURL("http://www.example.org/p/q/t"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9057 | request.traffic_annotation = |
| 9058 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9059 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9060 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9061 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9062 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9063 | MockWrite( |
| 9064 | "GET /p/q/t HTTP/1.1\r\n" |
| 9065 | "Host: www.example.org\r\n" |
| 9066 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9067 | }; |
| 9068 | |
| 9069 | MockRead data_reads1[] = { |
| 9070 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9071 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9072 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9073 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9074 | }; |
| 9075 | |
| 9076 | // Resend with authorization from cache for MyRealm. |
| 9077 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9078 | MockWrite( |
| 9079 | "GET /p/q/t HTTP/1.1\r\n" |
| 9080 | "Host: www.example.org\r\n" |
| 9081 | "Connection: keep-alive\r\n" |
| 9082 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9083 | }; |
| 9084 | |
| 9085 | // Sever rejects the authorization. |
| 9086 | MockRead data_reads2[] = { |
| 9087 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9088 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9089 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9090 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9091 | }; |
| 9092 | |
| 9093 | // At this point we should prompt for new credentials for MyRealm. |
| 9094 | // Restart with username=foo3, password=foo4. |
| 9095 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9096 | MockWrite( |
| 9097 | "GET /p/q/t HTTP/1.1\r\n" |
| 9098 | "Host: www.example.org\r\n" |
| 9099 | "Connection: keep-alive\r\n" |
| 9100 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9101 | }; |
| 9102 | |
| 9103 | // Sever accepts the authorization. |
| 9104 | MockRead data_reads3[] = { |
| 9105 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9106 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9107 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9108 | }; |
| 9109 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9110 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9111 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 9112 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9113 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9114 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9115 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9116 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9117 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9118 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9119 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9120 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9121 | |
| 9122 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9123 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9124 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9125 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9126 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9127 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9128 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9129 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9130 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9131 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9132 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9133 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9134 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9135 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9136 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9137 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9138 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9139 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 9140 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9141 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9142 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9143 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9144 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9145 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9146 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9147 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9148 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9149 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9150 | } |
| 9151 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9152 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9153 | // Tests that nonce count increments when multiple auth attempts |
| 9154 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9155 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 9156 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 9157 | new HttpAuthHandlerDigest::Factory(); |
| 9158 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 9159 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 9160 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9161 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9162 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9163 | |
| 9164 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 9165 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9166 | HttpRequestInfo request; |
| 9167 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9168 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9169 | request.traffic_annotation = |
| 9170 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9171 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9172 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9173 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9174 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9175 | MockWrite( |
| 9176 | "GET /x/y/z HTTP/1.1\r\n" |
| 9177 | "Host: www.example.org\r\n" |
| 9178 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9179 | }; |
| 9180 | |
| 9181 | MockRead data_reads1[] = { |
| 9182 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9183 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 9184 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9185 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9186 | }; |
| 9187 | |
| 9188 | // Resend with authorization (username=foo, password=bar) |
| 9189 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9190 | MockWrite( |
| 9191 | "GET /x/y/z HTTP/1.1\r\n" |
| 9192 | "Host: www.example.org\r\n" |
| 9193 | "Connection: keep-alive\r\n" |
| 9194 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9195 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 9196 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 9197 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9198 | }; |
| 9199 | |
| 9200 | // Sever accepts the authorization. |
| 9201 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9202 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9203 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9204 | }; |
| 9205 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9206 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9207 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9208 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9209 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9210 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9211 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9212 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9213 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9214 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9215 | |
| 9216 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9217 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9218 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9219 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9220 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9221 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9222 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9223 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9224 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9225 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9226 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9227 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9228 | |
| 9229 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9230 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9231 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9232 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9233 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9234 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9235 | } |
| 9236 | |
| 9237 | // ------------------------------------------------------------------------ |
| 9238 | |
| 9239 | // Transaction 2: Request another resource in digestive's protection space. |
| 9240 | // This will preemptively add an Authorization header which should have an |
| 9241 | // "nc" value of 2 (as compared to 1 in the first use. |
| 9242 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9243 | HttpRequestInfo request; |
| 9244 | request.method = "GET"; |
| 9245 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 9246 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9247 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9248 | request.traffic_annotation = |
| 9249 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9250 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9251 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9252 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9253 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9254 | MockWrite( |
| 9255 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 9256 | "Host: www.example.org\r\n" |
| 9257 | "Connection: keep-alive\r\n" |
| 9258 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9259 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 9260 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 9261 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9262 | }; |
| 9263 | |
| 9264 | // Sever accepts the authorization. |
| 9265 | MockRead data_reads1[] = { |
| 9266 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9267 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9268 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9269 | }; |
| 9270 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9271 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9272 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9273 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9274 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9275 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9276 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9277 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9278 | |
| 9279 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9280 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9281 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9282 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9283 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9284 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9285 | } |
| 9286 | } |
| 9287 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9288 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9289 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9290 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9291 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9292 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9293 | |
| 9294 | // Setup some state (which we expect ResetStateForRestart() will clear). |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 9295 | trans.read_buf_ = base::MakeRefCounted<IOBuffer>(15); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9296 | trans.read_buf_len_ = 15; |
| 9297 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9298 | |
| 9299 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9300 | HttpResponseInfo* response = &trans.response_; |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9301 | response->auth_challenge = base::nullopt; |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9302 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9303 | response->response_time = base::Time::Now(); |
| 9304 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9305 | |
| 9306 | { // Setup state for response_.vary_data |
| 9307 | HttpRequestInfo request; |
| 9308 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 9309 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 9310 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9311 | request.extra_headers.SetHeader("Foo", "1"); |
| 9312 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9313 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9314 | } |
| 9315 | |
| 9316 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9317 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9318 | |
| 9319 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9320 | EXPECT_FALSE(trans.read_buf_); |
| 9321 | EXPECT_EQ(0, trans.read_buf_len_); |
| 9322 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9323 | EXPECT_FALSE(response->auth_challenge.has_value()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9324 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 9325 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9326 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9327 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9328 | } |
| 9329 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9330 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9331 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9332 | HttpRequestInfo request; |
| 9333 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9334 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9335 | request.traffic_annotation = |
| 9336 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9337 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9338 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9339 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9340 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9341 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9342 | MockWrite( |
| 9343 | "GET / HTTP/1.1\r\n" |
| 9344 | "Host: www.example.org\r\n" |
| 9345 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9346 | }; |
| 9347 | |
| 9348 | MockRead data_reads[] = { |
| 9349 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9350 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9351 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9352 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9353 | }; |
| 9354 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 9355 | StaticSocketDataProvider ssl_bad_certificate; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9356 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9357 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9358 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9359 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9360 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9361 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9362 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9363 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9364 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9365 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9366 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9367 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9368 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9369 | |
| 9370 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9371 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9372 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9373 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9374 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9375 | |
| 9376 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9377 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9378 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9379 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9380 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9381 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9382 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9383 | } |
| 9384 | |
| 9385 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 9386 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9387 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9388 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9389 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9390 | |
| 9391 | HttpRequestInfo request; |
| 9392 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9393 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9394 | request.traffic_annotation = |
| 9395 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9396 | |
| 9397 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9398 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9399 | "Host: www.example.org:443\r\n" |
| 9400 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9401 | }; |
| 9402 | |
| 9403 | MockRead proxy_reads[] = { |
| 9404 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9405 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9406 | }; |
| 9407 | |
| 9408 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9409 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9410 | "Host: www.example.org:443\r\n" |
| 9411 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9412 | MockWrite("GET / HTTP/1.1\r\n" |
| 9413 | "Host: www.example.org\r\n" |
| 9414 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9415 | }; |
| 9416 | |
| 9417 | MockRead data_reads[] = { |
| 9418 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9419 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9420 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9421 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9422 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9423 | }; |
| 9424 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9425 | StaticSocketDataProvider ssl_bad_certificate(proxy_reads, proxy_writes); |
| 9426 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9427 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9428 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9429 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9430 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9431 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9432 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9433 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9434 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9435 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9436 | |
| 9437 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9438 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9439 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9440 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9441 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9442 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9443 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9444 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9445 | |
| 9446 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9447 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9448 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9449 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9450 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9451 | |
| 9452 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9453 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9454 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9455 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9456 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9457 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9458 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9459 | } |
| 9460 | } |
| 9461 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9462 | |
| 9463 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9464 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9465 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9466 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9467 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9468 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9469 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9470 | |
| 9471 | HttpRequestInfo request; |
| 9472 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9473 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9474 | request.traffic_annotation = |
| 9475 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9476 | |
| 9477 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9478 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9479 | "Host: www.example.org:443\r\n" |
| 9480 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9481 | MockWrite("GET / HTTP/1.1\r\n" |
| 9482 | "Host: www.example.org\r\n" |
| 9483 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9484 | }; |
| 9485 | |
| 9486 | MockRead data_reads[] = { |
| 9487 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9488 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9489 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9490 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9491 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9492 | }; |
| 9493 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9494 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9495 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9496 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9497 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9498 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9499 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9500 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9501 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9502 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9503 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9504 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9505 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9506 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9507 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9508 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9509 | |
| 9510 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9511 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9512 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9513 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9514 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9515 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9516 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9517 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9518 | EXPECT_EQ(200, response->headers->response_code()); |
| 9519 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9520 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9521 | |
| 9522 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9523 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9524 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9525 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9526 | } |
| 9527 | |
Eric Roman | 695a787 | 2019-04-16 21:53:29 | [diff] [blame] | 9528 | // Test that an HTTPS Proxy cannot redirect a CONNECT request for main frames. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9529 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9530 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9531 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9532 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9533 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9534 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9535 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9536 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 9537 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 9538 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9539 | HttpRequestInfo request; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9540 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9541 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9542 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9543 | request.traffic_annotation = |
| 9544 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9545 | |
| 9546 | MockWrite data_writes[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9547 | MockWrite(ASYNC, 0, |
| 9548 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9549 | "Host: www.example.org:443\r\n" |
| 9550 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9551 | }; |
| 9552 | |
| 9553 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9554 | // Pause on first read. |
| 9555 | MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 9556 | MockRead(ASYNC, 2, "HTTP/1.1 302 Redirect\r\n"), |
| 9557 | MockRead(ASYNC, 3, "Location: http://login.example.com/\r\n"), |
| 9558 | MockRead(ASYNC, 4, "Content-Length: 0\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9559 | }; |
| 9560 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9561 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9562 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9563 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9564 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9565 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9566 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9567 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9568 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9569 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9570 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9571 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9572 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9573 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9574 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
| 9575 | |
| 9576 | // Host resolution takes |kTimeIncrement|. |
| 9577 | FastForwardBy(kTimeIncrement); |
| 9578 | // Resolving the current request with |ResolveNow| will cause the pending |
| 9579 | // request to instantly complete, and the async connect will start as well. |
| 9580 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 9581 | |
| 9582 | // Connecting takes |kTimeIncrement|. |
| 9583 | FastForwardBy(kTimeIncrement); |
| 9584 | data.RunUntilPaused(); |
| 9585 | |
| 9586 | // The server takes |kTimeIncrement| to respond. |
| 9587 | FastForwardBy(kTimeIncrement); |
| 9588 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9589 | |
| 9590 | rv = callback.WaitForResult(); |
Eric Roman | 695a787 | 2019-04-16 21:53:29 | [diff] [blame] | 9591 | EXPECT_THAT(rv, IsError(ERR_HTTPS_PROXY_TUNNEL_RESPONSE_REDIRECT)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9592 | } |
| 9593 | |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9594 | // Test that an HTTPS Proxy cannot redirect a CONNECT request for subresources. |
| 9595 | TEST_F(HttpNetworkTransactionTest, |
| 9596 | RedirectOfHttpsConnectSubresourceViaHttpsProxy) { |
| 9597 | base::HistogramTester histograms; |
| 9598 | session_deps_.proxy_resolution_service = |
| 9599 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9600 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9601 | TestNetLog net_log; |
| 9602 | session_deps_.net_log = &net_log; |
| 9603 | |
| 9604 | HttpRequestInfo request; |
| 9605 | request.method = "GET"; |
| 9606 | request.url = GURL("https://www.example.org/"); |
| 9607 | request.traffic_annotation = |
| 9608 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9609 | |
| 9610 | MockWrite data_writes[] = { |
| 9611 | MockWrite(ASYNC, 0, |
| 9612 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9613 | "Host: www.example.org:443\r\n" |
| 9614 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9615 | }; |
| 9616 | |
| 9617 | MockRead data_reads[] = { |
| 9618 | MockRead(ASYNC, 1, "HTTP/1.1 302 Redirect\r\n"), |
| 9619 | MockRead(ASYNC, 2, "Location: http://login.example.com/\r\n"), |
| 9620 | MockRead(ASYNC, 3, "Content-Length: 0\r\n\r\n"), |
| 9621 | }; |
| 9622 | |
| 9623 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
| 9624 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9625 | |
| 9626 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9627 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9628 | |
| 9629 | TestCompletionCallback callback; |
| 9630 | |
| 9631 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9632 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 9633 | |
| 9634 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 9635 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9636 | |
| 9637 | rv = callback.WaitForResult(); |
| 9638 | EXPECT_THAT(rv, IsError(ERR_HTTPS_PROXY_TUNNEL_RESPONSE_REDIRECT)); |
| 9639 | |
| 9640 | histograms.ExpectUniqueSample( |
| 9641 | "Net.Proxy.RedirectDuringConnect", |
| 9642 | HttpNetworkTransaction::kSubresourceByExplicitProxy, 1); |
| 9643 | } |
| 9644 | |
| 9645 | // Test that an HTTPS Proxy which was auto-detected cannot redirect a CONNECT |
| 9646 | // request for main frames. |
| 9647 | TEST_F(HttpNetworkTransactionTest, |
| 9648 | RedirectOfHttpsConnectViaAutoDetectedHttpsProxy) { |
| 9649 | base::HistogramTester histograms; |
| 9650 | session_deps_.proxy_resolution_service = |
| 9651 | ProxyResolutionService::CreateFixedFromAutoDetectedPacResult( |
| 9652 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9653 | TestNetLog net_log; |
| 9654 | session_deps_.net_log = &net_log; |
| 9655 | |
| 9656 | HttpRequestInfo request; |
| 9657 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
| 9658 | request.method = "GET"; |
| 9659 | request.url = GURL("https://www.example.org/"); |
| 9660 | request.traffic_annotation = |
| 9661 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9662 | |
| 9663 | MockWrite data_writes[] = { |
| 9664 | MockWrite(ASYNC, 0, |
| 9665 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9666 | "Host: www.example.org:443\r\n" |
| 9667 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9668 | }; |
| 9669 | |
| 9670 | MockRead data_reads[] = { |
| 9671 | MockRead(ASYNC, 1, "HTTP/1.1 302 Redirect\r\n"), |
| 9672 | MockRead(ASYNC, 2, "Location: http://login.example.com/\r\n"), |
| 9673 | MockRead(ASYNC, 3, "Content-Length: 0\r\n\r\n"), |
| 9674 | }; |
| 9675 | |
| 9676 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
| 9677 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9678 | |
| 9679 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9680 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9681 | |
| 9682 | TestCompletionCallback callback; |
| 9683 | |
| 9684 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9685 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 9686 | |
| 9687 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 9688 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9689 | |
| 9690 | rv = callback.WaitForResult(); |
| 9691 | EXPECT_THAT(rv, IsError(ERR_HTTPS_PROXY_TUNNEL_RESPONSE_REDIRECT)); |
| 9692 | |
| 9693 | histograms.ExpectUniqueSample( |
| 9694 | "Net.Proxy.RedirectDuringConnect", |
| 9695 | HttpNetworkTransaction::kMainFrameByAutoDetectedProxy, 1); |
| 9696 | } |
| 9697 | |
Eric Roman | 695a787 | 2019-04-16 21:53:29 | [diff] [blame] | 9698 | // Tests that an HTTPS (SPDY) Proxy's cannot redirect a CONNECT request for main |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9699 | // frames. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9700 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9701 | base::HistogramTester histograms; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9702 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9703 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9704 | TestNetLog net_log; |
| 9705 | session_deps_.net_log = &net_log; |
| 9706 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9707 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 9708 | session_deps_.host_resolver->set_ondemand_mode(true); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9709 | |
| 9710 | HttpRequestInfo request; |
| 9711 | request.method = "GET"; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9712 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9713 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9714 | request.traffic_annotation = |
| 9715 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9716 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9717 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9718 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 9719 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9720 | spdy::SpdySerializedFrame goaway( |
| 9721 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9722 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9723 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9724 | CreateMockWrite(goaway, 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9725 | }; |
| 9726 | |
| 9727 | static const char* const kExtraHeaders[] = { |
| 9728 | "location", |
| 9729 | "http://login.example.com/", |
| 9730 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9731 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9732 | "302", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9733 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9734 | // Pause on first read. |
| 9735 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp, 2), |
| 9736 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9737 | }; |
| 9738 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9739 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9740 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9741 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9742 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9743 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9744 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9745 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9746 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9747 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9748 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9749 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9750 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9751 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9752 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9753 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9754 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9755 | // Host resolution takes |kTimeIncrement|. |
| 9756 | FastForwardBy(kTimeIncrement); |
| 9757 | // Resolving the current request with |ResolveNow| will cause the pending |
| 9758 | // request to instantly complete, and the async connect will start as well. |
| 9759 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 9760 | |
| 9761 | // Connecting takes |kTimeIncrement|. |
| 9762 | FastForwardBy(kTimeIncrement); |
| 9763 | data.RunUntilPaused(); |
| 9764 | |
| 9765 | FastForwardBy(kTimeIncrement); |
| 9766 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9767 | rv = callback.WaitForResult(); |
Eric Roman | 695a787 | 2019-04-16 21:53:29 | [diff] [blame] | 9768 | EXPECT_THAT(rv, IsError(ERR_HTTPS_PROXY_TUNNEL_RESPONSE_REDIRECT)); |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9769 | |
| 9770 | histograms.ExpectUniqueSample( |
| 9771 | "Net.Proxy.RedirectDuringConnect", |
| 9772 | HttpNetworkTransaction::kMainFrameByExplicitProxy, 1); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9773 | } |
| 9774 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 9775 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9776 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9777 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9778 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9779 | |
| 9780 | HttpRequestInfo request; |
| 9781 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9782 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9783 | request.traffic_annotation = |
| 9784 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9785 | |
| 9786 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9787 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9788 | "Host: www.example.org:443\r\n" |
| 9789 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9790 | }; |
| 9791 | |
| 9792 | MockRead data_reads[] = { |
| 9793 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 9794 | MockRead("Content-Length: 23\r\n\r\n"), |
| 9795 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9796 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9797 | }; |
| 9798 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9799 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9800 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9801 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9802 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9803 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9804 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9805 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9806 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9807 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9808 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9809 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9810 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9811 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9812 | |
| 9813 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9814 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9815 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 9816 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9817 | } |
| 9818 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 9819 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9820 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9821 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9822 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9823 | |
| 9824 | HttpRequestInfo request; |
| 9825 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9826 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9827 | request.traffic_annotation = |
| 9828 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9829 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9830 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9831 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 9832 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9833 | spdy::SpdySerializedFrame rst( |
| 9834 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9835 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9836 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9837 | }; |
| 9838 | |
| 9839 | static const char* const kExtraHeaders[] = { |
| 9840 | "location", |
| 9841 | "http://login.example.com/", |
| 9842 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9843 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9844 | "404", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9845 | spdy::SpdySerializedFrame body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9846 | spdy_util_.ConstructSpdyDataFrame(1, "The host does not exist", true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9847 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9848 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9849 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9850 | }; |
| 9851 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9852 | SequencedSocketData data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9853 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9854 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9855 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9856 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9857 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9858 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9859 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9860 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9861 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9862 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9863 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9864 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9865 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9866 | |
| 9867 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9868 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9869 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 9870 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9871 | } |
| 9872 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9873 | // Test the request-challenge-retry sequence for basic auth, through |
| 9874 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9875 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9876 | HttpRequestInfo request; |
| 9877 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9878 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9879 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 9880 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9881 | request.traffic_annotation = |
| 9882 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9883 | |
| 9884 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9885 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9886 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9887 | "HTTPS myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9888 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9889 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9890 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9891 | |
| 9892 | // Since we have proxy, should try to establish tunnel. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9893 | spdy::SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9894 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 9895 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9896 | spdy::SpdySerializedFrame rst( |
| 9897 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9898 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9899 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9900 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9901 | // be issuing -- the final header line contains the credentials. |
| 9902 | const char* const kAuthCredentials[] = { |
| 9903 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 9904 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9905 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9906 | kAuthCredentials, base::size(kAuthCredentials) / 2, 3, |
| 9907 | HttpProxyConnectJob::kH2QuicTunnelPriority, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9908 | HostPortPair("www.example.org", 443))); |
| 9909 | // fetch https://www.example.org/ via HTTP |
| 9910 | const char get[] = |
| 9911 | "GET / HTTP/1.1\r\n" |
| 9912 | "Host: www.example.org\r\n" |
| 9913 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9914 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9915 | spdy_util_.ConstructSpdyDataFrame(3, get, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9916 | |
| 9917 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9918 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 9919 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9920 | }; |
| 9921 | |
| 9922 | // The proxy responds to the connect with a 407, using a persistent |
| 9923 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 9924 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9925 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9926 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 9927 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9928 | spdy::SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9929 | kAuthStatus, kAuthChallenge, base::size(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9930 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9931 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 9932 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9933 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 9934 | "Content-Length: 5\r\n\r\n"; |
| 9935 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9936 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9937 | spdy_util_.ConstructSpdyDataFrame(3, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9938 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9939 | spdy_util_.ConstructSpdyDataFrame(3, "hello", false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9940 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9941 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 9942 | CreateMockRead(conn_resp, 4, ASYNC), |
| 9943 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 9944 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9945 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9946 | }; |
| 9947 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9948 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9949 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9950 | // Negotiate SPDY to the proxy |
| 9951 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9952 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9953 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9954 | // Vanilla SSL to the server |
| 9955 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9956 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9957 | |
| 9958 | TestCompletionCallback callback1; |
| 9959 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9960 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9961 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9962 | |
| 9963 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9964 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9965 | |
| 9966 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9967 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 9968 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9969 | log.GetEntries(&entries); |
| 9970 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 9971 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 9972 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9973 | ExpectLogContainsSomewhere( |
| 9974 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 9975 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 9976 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9977 | |
| 9978 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9979 | ASSERT_TRUE(response); |
| 9980 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9981 | EXPECT_EQ(407, response->headers->response_code()); |
| 9982 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9983 | EXPECT_TRUE(response->auth_challenge.has_value()); |
| 9984 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9985 | |
| 9986 | TestCompletionCallback callback2; |
| 9987 | |
| 9988 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9989 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9990 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9991 | |
| 9992 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9993 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9994 | |
| 9995 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9996 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9997 | |
| 9998 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9999 | EXPECT_EQ(200, response->headers->response_code()); |
| 10000 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 10001 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10002 | |
| 10003 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10004 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10005 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10006 | LoadTimingInfo load_timing_info; |
| 10007 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10008 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10009 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10010 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10011 | trans.reset(); |
| 10012 | session->CloseAllConnections(); |
| 10013 | } |
| 10014 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10015 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 10016 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10017 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10018 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10019 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10020 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 10021 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10022 | HttpRequestInfo request; |
| 10023 | HttpRequestInfo push_request; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10024 | request.traffic_annotation = |
| 10025 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10026 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10027 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10028 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10029 | push_request.method = "GET"; |
| 10030 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10031 | push_request.traffic_annotation = |
| 10032 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10033 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10034 | // Configure against https proxy server "myproxy:443". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10035 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10036 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10037 | "HTTPS myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10038 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10039 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10040 | |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10041 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10042 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10043 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10044 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10045 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10046 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10047 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10048 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10049 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10050 | |
| 10051 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10052 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10053 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10054 | }; |
| 10055 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10056 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10057 | nullptr, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 10058 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10059 | spdy::SpdySerializedFrame stream1_reply( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10060 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10061 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10062 | spdy::SpdySerializedFrame stream1_body( |
| 10063 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10064 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10065 | spdy::SpdySerializedFrame stream2_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 10066 | spdy_util_.ConstructSpdyDataFrame(2, "pushed", true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10067 | |
| 10068 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 10069 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 10070 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10071 | CreateMockRead(stream1_body, 4, ASYNC), |
| 10072 | CreateMockRead(stream2_body, 5, ASYNC), |
| 10073 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10074 | }; |
| 10075 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10076 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10077 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10078 | // Negotiate SPDY to the proxy |
| 10079 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10080 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10081 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10082 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10083 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10084 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10085 | TestCompletionCallback callback; |
| 10086 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10087 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10088 | |
| 10089 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10090 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10091 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10092 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10093 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10094 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10095 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10096 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10097 | |
| 10098 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10099 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10100 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 10101 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10102 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10103 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10104 | |
| 10105 | EXPECT_EQ(200, response->headers->response_code()); |
| 10106 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10107 | |
| 10108 | std::string response_data; |
| 10109 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10110 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10111 | EXPECT_EQ("hello!", response_data); |
| 10112 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10113 | LoadTimingInfo load_timing_info; |
| 10114 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10115 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10116 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10117 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10118 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10119 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10120 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 10121 | |
| 10122 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10123 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10124 | EXPECT_EQ("pushed", response_data); |
| 10125 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10126 | LoadTimingInfo push_load_timing_info; |
| 10127 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 10128 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 10129 | // The transactions should share a socket ID, despite being for different |
| 10130 | // origins. |
| 10131 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 10132 | push_load_timing_info.socket_log_id); |
| 10133 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10134 | trans.reset(); |
| 10135 | push_trans.reset(); |
| 10136 | session->CloseAllConnections(); |
| 10137 | } |
| 10138 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10139 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10140 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10141 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10142 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10143 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 10144 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10145 | HttpRequestInfo request; |
| 10146 | |
| 10147 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10148 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10149 | request.traffic_annotation = |
| 10150 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10151 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10152 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10153 | "https://myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10154 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10155 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10156 | |
| 10157 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10158 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10159 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10160 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10161 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10162 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10163 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10164 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10165 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10166 | spdy::SpdySerializedFrame push_rst( |
| 10167 | spdy_util_.ConstructSpdyRstStream(2, spdy::ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10168 | |
| 10169 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10170 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10171 | }; |
| 10172 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10173 | spdy::SpdySerializedFrame stream1_reply( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10174 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10175 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10176 | spdy::SpdySerializedFrame stream1_body( |
| 10177 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10178 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10179 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10180 | nullptr, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10181 | |
| 10182 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10183 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10184 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 10185 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 10186 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10187 | }; |
| 10188 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10189 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10190 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10191 | // Negotiate SPDY to the proxy |
| 10192 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10193 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10194 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10195 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10196 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10197 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10198 | TestCompletionCallback callback; |
| 10199 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10200 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10201 | |
| 10202 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10203 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10204 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10205 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10206 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10207 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10208 | |
| 10209 | EXPECT_EQ(200, response->headers->response_code()); |
| 10210 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10211 | |
| 10212 | std::string response_data; |
| 10213 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10214 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10215 | EXPECT_EQ("hello!", response_data); |
| 10216 | |
| 10217 | trans.reset(); |
| 10218 | session->CloseAllConnections(); |
| 10219 | } |
| 10220 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10221 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 10222 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10223 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10224 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10225 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10226 | proxy_delegate->set_trusted_spdy_proxy( |
| 10227 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 10228 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10229 | HttpRequestInfo request; |
| 10230 | |
| 10231 | request.method = "GET"; |
| 10232 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10233 | request.traffic_annotation = |
| 10234 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10235 | |
| 10236 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10237 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10238 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10239 | BoundTestNetLog log; |
| 10240 | session_deps_.net_log = log.bound().net_log(); |
| 10241 | |
| 10242 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10243 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10244 | proxy_delegate.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10245 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10246 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10247 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10248 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10249 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10250 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10251 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10252 | |
| 10253 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10254 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10255 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10256 | }; |
| 10257 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10258 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10259 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10260 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10261 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 10262 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 10263 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10264 | spdy::SpdySerializedFrame stream1_body( |
| 10265 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10266 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10267 | spdy::SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10268 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10269 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10270 | spdy::SpdySerializedFrame stream2_body( |
| 10271 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10272 | |
| 10273 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10274 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10275 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10276 | CreateMockRead(stream1_body, 4, ASYNC), |
| 10277 | CreateMockRead(stream2_body, 5, ASYNC), |
| 10278 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10279 | }; |
| 10280 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10281 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10282 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 10283 | // Negotiate SPDY to the proxy |
| 10284 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10285 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10286 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 10287 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10288 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10289 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10290 | TestCompletionCallback callback; |
| 10291 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10292 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10293 | |
| 10294 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10295 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10296 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10297 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10298 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10299 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10300 | |
| 10301 | EXPECT_EQ(200, response->headers->response_code()); |
| 10302 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10303 | |
| 10304 | std::string response_data; |
| 10305 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10306 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10307 | EXPECT_EQ("hello!", response_data); |
| 10308 | |
| 10309 | trans.reset(); |
| 10310 | session->CloseAllConnections(); |
| 10311 | } |
| 10312 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10313 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 10314 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10315 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10316 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10317 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10318 | |
| 10319 | HttpRequestInfo request; |
| 10320 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10321 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10322 | request.traffic_annotation = |
| 10323 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10324 | |
| 10325 | // Attempt to fetch the URL from a server with a bad cert |
| 10326 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10327 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10328 | "Host: www.example.org:443\r\n" |
| 10329 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10330 | }; |
| 10331 | |
| 10332 | MockRead bad_cert_reads[] = { |
| 10333 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10334 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10335 | }; |
| 10336 | |
| 10337 | // Attempt to fetch the URL with a good cert |
| 10338 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10339 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10340 | "Host: www.example.org:443\r\n" |
| 10341 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10342 | MockWrite("GET / HTTP/1.1\r\n" |
| 10343 | "Host: www.example.org\r\n" |
| 10344 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10345 | }; |
| 10346 | |
| 10347 | MockRead good_cert_reads[] = { |
| 10348 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 10349 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10350 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10351 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10352 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10353 | }; |
| 10354 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10355 | StaticSocketDataProvider ssl_bad_certificate(bad_cert_reads, bad_cert_writes); |
| 10356 | StaticSocketDataProvider data(good_cert_reads, good_data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10357 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 10358 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10359 | |
| 10360 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10361 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10362 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 10363 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10364 | |
| 10365 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10366 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10367 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10368 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10369 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10370 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10371 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10372 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10373 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10374 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10375 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10376 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10377 | |
| 10378 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10379 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10380 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10381 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10382 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10383 | |
| 10384 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10385 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10386 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10387 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10388 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10389 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10390 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10391 | } |
| 10392 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10393 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10394 | HttpRequestInfo request; |
| 10395 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10396 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10397 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10398 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10399 | request.traffic_annotation = |
| 10400 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10401 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10402 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10403 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10404 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10405 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10406 | MockWrite( |
| 10407 | "GET / HTTP/1.1\r\n" |
| 10408 | "Host: www.example.org\r\n" |
| 10409 | "Connection: keep-alive\r\n" |
| 10410 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10411 | }; |
| 10412 | |
| 10413 | // Lastly, the server responds with the actual content. |
| 10414 | MockRead data_reads[] = { |
| 10415 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10416 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10417 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10418 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10419 | }; |
| 10420 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10421 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10422 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10423 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10424 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10425 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10426 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10427 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10428 | |
| 10429 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10430 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10431 | } |
| 10432 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10433 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10434 | // Test user agent values, used both for the request header of the original |
| 10435 | // request, and the value returned by the HttpUserAgentSettings. nullptr means |
| 10436 | // no request header / no HttpUserAgentSettings object. |
| 10437 | const char* kTestUserAgents[] = {nullptr, "", "Foopy"}; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10438 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10439 | for (const char* setting_user_agent : kTestUserAgents) { |
| 10440 | if (!setting_user_agent) { |
| 10441 | session_deps_.http_user_agent_settings.reset(); |
| 10442 | } else { |
| 10443 | session_deps_.http_user_agent_settings = |
| 10444 | std::make_unique<StaticHttpUserAgentSettings>( |
| 10445 | std::string() /* accept-language */, setting_user_agent); |
| 10446 | } |
| 10447 | session_deps_.proxy_resolution_service = |
| 10448 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 10449 | TRAFFIC_ANNOTATION_FOR_TESTS); |
| 10450 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10451 | for (const char* request_user_agent : kTestUserAgents) { |
| 10452 | HttpRequestInfo request; |
| 10453 | request.method = "GET"; |
| 10454 | request.url = GURL("https://www.example.org/"); |
| 10455 | if (request_user_agent) { |
| 10456 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10457 | request_user_agent); |
| 10458 | } |
| 10459 | request.traffic_annotation = |
| 10460 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10461 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10462 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10463 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10464 | std::string expected_request; |
| 10465 | if (!setting_user_agent || strlen(setting_user_agent) == 0) { |
| 10466 | expected_request = |
| 10467 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10468 | "Host: www.example.org:443\r\n" |
| 10469 | "Proxy-Connection: keep-alive\r\n\r\n"; |
| 10470 | } else { |
| 10471 | expected_request = base::StringPrintf( |
| 10472 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10473 | "Host: www.example.org:443\r\n" |
| 10474 | "Proxy-Connection: keep-alive\r\n" |
| 10475 | "User-Agent: %s\r\n\r\n", |
| 10476 | setting_user_agent); |
| 10477 | } |
| 10478 | MockWrite data_writes[] = { |
| 10479 | MockWrite(expected_request.c_str()), |
| 10480 | }; |
| 10481 | MockRead data_reads[] = { |
| 10482 | // Return an error, so the transaction stops here (this test isn't |
| 10483 | // interested in the rest). |
| 10484 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 10485 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10486 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 10487 | }; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10488 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10489 | StaticSocketDataProvider data(data_reads, data_writes); |
| 10490 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10491 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10492 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10493 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10494 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 10495 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10496 | |
| 10497 | rv = callback.WaitForResult(); |
| 10498 | EXPECT_THAT(rv, IsOk()); |
| 10499 | } |
| 10500 | } |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10501 | } |
| 10502 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10503 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10504 | HttpRequestInfo request; |
| 10505 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10506 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 10507 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 10508 | "http://the.previous.site.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10509 | request.traffic_annotation = |
| 10510 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10511 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10512 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10513 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10514 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10515 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10516 | MockWrite( |
| 10517 | "GET / HTTP/1.1\r\n" |
| 10518 | "Host: www.example.org\r\n" |
| 10519 | "Connection: keep-alive\r\n" |
| 10520 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10521 | }; |
| 10522 | |
| 10523 | // Lastly, the server responds with the actual content. |
| 10524 | MockRead data_reads[] = { |
| 10525 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10526 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10527 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10528 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10529 | }; |
| 10530 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10531 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10532 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10533 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10534 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10535 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10536 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10537 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10538 | |
| 10539 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10540 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10541 | } |
| 10542 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10543 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10544 | HttpRequestInfo request; |
| 10545 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10546 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10547 | request.traffic_annotation = |
| 10548 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10549 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10550 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10551 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10552 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10553 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10554 | MockWrite( |
| 10555 | "POST / HTTP/1.1\r\n" |
| 10556 | "Host: www.example.org\r\n" |
| 10557 | "Connection: keep-alive\r\n" |
| 10558 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10559 | }; |
| 10560 | |
| 10561 | // Lastly, the server responds with the actual content. |
| 10562 | MockRead data_reads[] = { |
| 10563 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10564 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10565 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10566 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10567 | }; |
| 10568 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10569 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10570 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10571 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10572 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10573 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10574 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10575 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10576 | |
| 10577 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10578 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10579 | } |
| 10580 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10581 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10582 | HttpRequestInfo request; |
| 10583 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10584 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10585 | request.traffic_annotation = |
| 10586 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10587 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10588 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10589 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10590 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10591 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10592 | MockWrite( |
| 10593 | "PUT / HTTP/1.1\r\n" |
| 10594 | "Host: www.example.org\r\n" |
| 10595 | "Connection: keep-alive\r\n" |
| 10596 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10597 | }; |
| 10598 | |
| 10599 | // Lastly, the server responds with the actual content. |
| 10600 | MockRead data_reads[] = { |
| 10601 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10602 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10603 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10604 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10605 | }; |
| 10606 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10607 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10608 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10609 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10610 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10611 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10612 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10613 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10614 | |
| 10615 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10616 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10617 | } |
| 10618 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10619 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10620 | HttpRequestInfo request; |
| 10621 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10622 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10623 | request.traffic_annotation = |
| 10624 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10625 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10626 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10627 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10628 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10629 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 10630 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 10631 | "Host: www.example.org\r\n" |
| 10632 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10633 | }; |
| 10634 | |
| 10635 | // Lastly, the server responds with the actual content. |
| 10636 | MockRead data_reads[] = { |
| 10637 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10638 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10639 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10640 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10641 | }; |
| 10642 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10643 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10644 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10645 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10646 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10647 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10648 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10649 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10650 | |
| 10651 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10652 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10653 | } |
| 10654 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10655 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10656 | HttpRequestInfo request; |
| 10657 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10658 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10659 | request.load_flags = LOAD_BYPASS_CACHE; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10660 | request.traffic_annotation = |
| 10661 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10662 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10663 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10664 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10665 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10666 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10667 | MockWrite( |
| 10668 | "GET / HTTP/1.1\r\n" |
| 10669 | "Host: www.example.org\r\n" |
| 10670 | "Connection: keep-alive\r\n" |
| 10671 | "Pragma: no-cache\r\n" |
| 10672 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10673 | }; |
| 10674 | |
| 10675 | // Lastly, the server responds with the actual content. |
| 10676 | MockRead data_reads[] = { |
| 10677 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10678 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10679 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10680 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10681 | }; |
| 10682 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10683 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10684 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10685 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10686 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10687 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10688 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10689 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10690 | |
| 10691 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10692 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10693 | } |
| 10694 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10695 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10696 | HttpRequestInfo request; |
| 10697 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10698 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10699 | request.load_flags = LOAD_VALIDATE_CACHE; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10700 | request.traffic_annotation = |
| 10701 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10702 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10703 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10704 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10705 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10706 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10707 | MockWrite( |
| 10708 | "GET / HTTP/1.1\r\n" |
| 10709 | "Host: www.example.org\r\n" |
| 10710 | "Connection: keep-alive\r\n" |
| 10711 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10712 | }; |
| 10713 | |
| 10714 | // Lastly, the server responds with the actual content. |
| 10715 | MockRead data_reads[] = { |
| 10716 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10717 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10718 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10719 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10720 | }; |
| 10721 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10722 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10723 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10724 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10725 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10726 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10727 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10728 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10729 | |
| 10730 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10731 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10732 | } |
| 10733 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10734 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10735 | HttpRequestInfo request; |
| 10736 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10737 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10738 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10739 | request.traffic_annotation = |
| 10740 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10741 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10742 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10743 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10744 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10745 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10746 | MockWrite( |
| 10747 | "GET / HTTP/1.1\r\n" |
| 10748 | "Host: www.example.org\r\n" |
| 10749 | "Connection: keep-alive\r\n" |
| 10750 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10751 | }; |
| 10752 | |
| 10753 | // Lastly, the server responds with the actual content. |
| 10754 | MockRead data_reads[] = { |
| 10755 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10756 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10757 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10758 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10759 | }; |
| 10760 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10761 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10762 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10763 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10764 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10765 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10766 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10767 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10768 | |
| 10769 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10770 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10771 | } |
| 10772 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10773 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10774 | HttpRequestInfo request; |
| 10775 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10776 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10777 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 10778 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 10779 | request.extra_headers.SetHeader("FoO", "bar"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10780 | request.traffic_annotation = |
| 10781 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10782 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10783 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10784 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10785 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10786 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10787 | MockWrite( |
| 10788 | "GET / HTTP/1.1\r\n" |
| 10789 | "Host: www.example.org\r\n" |
| 10790 | "Connection: keep-alive\r\n" |
| 10791 | "referer: www.foo.com\r\n" |
| 10792 | "hEllo: Kitty\r\n" |
| 10793 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10794 | }; |
| 10795 | |
| 10796 | // Lastly, the server responds with the actual content. |
| 10797 | MockRead data_reads[] = { |
| 10798 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10799 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10800 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10801 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10802 | }; |
| 10803 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10804 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10805 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10806 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10807 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10808 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10809 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10810 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10811 | |
| 10812 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10813 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10814 | } |
| 10815 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10816 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10817 | HttpRequestInfo request; |
| 10818 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10819 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10820 | request.traffic_annotation = |
| 10821 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10822 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10823 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10824 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10825 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10826 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10827 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10828 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10829 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10830 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10831 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10832 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 10833 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10834 | |
| 10835 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10836 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 10837 | MockWrite("GET / HTTP/1.1\r\n" |
| 10838 | "Host: www.example.org\r\n" |
| 10839 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10840 | |
| 10841 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10842 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 10843 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10844 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10845 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10846 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10847 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10848 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10849 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10850 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10851 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10852 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10853 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10854 | |
| 10855 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10856 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10857 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10858 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10859 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10860 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10861 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10862 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10863 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10864 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10865 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10866 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10867 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10868 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10869 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10870 | EXPECT_EQ("Payload", response_text); |
| 10871 | } |
| 10872 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10873 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10874 | HttpRequestInfo request; |
| 10875 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10876 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10877 | request.traffic_annotation = |
| 10878 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10879 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10880 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10881 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10882 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10883 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10884 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10885 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10886 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10887 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10888 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10889 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 10890 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10891 | |
| 10892 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10893 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10894 | base::size(write_buffer)), |
| 10895 | MockWrite("GET / HTTP/1.1\r\n" |
| 10896 | "Host: www.example.org\r\n" |
| 10897 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10898 | |
| 10899 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10900 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 10901 | base::size(read_buffer)), |
| 10902 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10903 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10904 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10905 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10906 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10907 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10908 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10909 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10910 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10911 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10912 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [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] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10916 | |
| 10917 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10918 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10919 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10920 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10921 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10922 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10923 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10924 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10925 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10926 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10927 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10928 | |
| 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] | e0c27be | 2009-07-15 13:09:35 | [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_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10936 | HttpRequestInfo request; |
| 10937 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10938 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10939 | request.traffic_annotation = |
| 10940 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10941 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10942 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10943 | "socks4://myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10944 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10945 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10946 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10947 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10948 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10949 | |
| 10950 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 10951 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10952 | |
| 10953 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10954 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 10955 | MockWrite("GET / HTTP/1.1\r\n" |
| 10956 | "Host: www.example.org\r\n" |
| 10957 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10958 | |
| 10959 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10960 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 10961 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10962 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10963 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10964 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10965 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10966 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10967 | |
| 10968 | TestCompletionCallback callback; |
| 10969 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10970 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10971 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10972 | |
| 10973 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10974 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10975 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10976 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10977 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10978 | |
| 10979 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10980 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10981 | TestLoadTimingNotReused(load_timing_info, |
| 10982 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10983 | |
| 10984 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10985 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10986 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10987 | EXPECT_EQ("Payload", response_text); |
| 10988 | } |
| 10989 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10990 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10991 | HttpRequestInfo request; |
| 10992 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10993 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10994 | request.traffic_annotation = |
| 10995 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10996 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10997 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10998 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10999 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11000 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11001 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11002 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11003 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11004 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11005 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11006 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 11007 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11008 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11009 | 0x05, // Version |
| 11010 | 0x01, // Command (CONNECT) |
| 11011 | 0x00, // Reserved. |
| 11012 | 0x03, // Address type (DOMAINNAME). |
| 11013 | 0x0F, // Length of domain (15) |
| 11014 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 11015 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11016 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11017 | const char kSOCKS5OkResponse[] = |
| 11018 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 11019 | |
| 11020 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11021 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
| 11022 | MockWrite(ASYNC, kSOCKS5OkRequest, base::size(kSOCKS5OkRequest)), |
| 11023 | MockWrite("GET / HTTP/1.1\r\n" |
| 11024 | "Host: www.example.org\r\n" |
| 11025 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11026 | |
| 11027 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11028 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 11029 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 11030 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11031 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11032 | MockRead("Payload"), |
| 11033 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11034 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11035 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11036 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11037 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11038 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11039 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11040 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11041 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11042 | |
| 11043 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11044 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11045 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11046 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11047 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11048 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11049 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11050 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11051 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11052 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11053 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 11054 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11055 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11056 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11057 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11058 | EXPECT_EQ("Payload", response_text); |
| 11059 | } |
| 11060 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11061 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11062 | HttpRequestInfo request; |
| 11063 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11064 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11065 | request.traffic_annotation = |
| 11066 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11067 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11068 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11069 | ProxyResolutionService::CreateFixedFromPacResult( |
| 11070 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11071 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11072 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11073 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11074 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11075 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11076 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11077 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 11078 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11079 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11080 | 0x05, // Version |
| 11081 | 0x01, // Command (CONNECT) |
| 11082 | 0x00, // Reserved. |
| 11083 | 0x03, // Address type (DOMAINNAME). |
| 11084 | 0x0F, // Length of domain (15) |
| 11085 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 11086 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11087 | }; |
| 11088 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11089 | const char kSOCKS5OkResponse[] = |
| 11090 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 11091 | |
| 11092 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11093 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11094 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11095 | base::size(kSOCKS5OkRequest)), |
| 11096 | MockWrite("GET / HTTP/1.1\r\n" |
| 11097 | "Host: www.example.org\r\n" |
| 11098 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11099 | |
| 11100 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11101 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 11102 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 11103 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11104 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11105 | MockRead("Payload"), |
| 11106 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11107 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11108 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11109 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11110 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11111 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11112 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11113 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11114 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11115 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11116 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11117 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11118 | |
| 11119 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11120 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11121 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11122 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11123 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11124 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11125 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11126 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11127 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11128 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11129 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 11130 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11131 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11132 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11133 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11134 | EXPECT_EQ("Payload", response_text); |
| 11135 | } |
| 11136 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11137 | namespace { |
| 11138 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11139 | // Tests that for connection endpoints the group ids are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11140 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11141 | struct GroupIdTest { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11142 | std::string proxy_server; |
| 11143 | std::string url; |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11144 | ClientSocketPool::GroupId expected_group_id; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 11145 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11146 | }; |
| 11147 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11148 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupIdTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11149 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11150 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11151 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11152 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11153 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11154 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11155 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11156 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 11157 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11158 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11159 | |
| 11160 | return session; |
| 11161 | } |
| 11162 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11163 | int GroupIdTransactionHelper(const std::string& url, |
| 11164 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11165 | HttpRequestInfo request; |
| 11166 | request.method = "GET"; |
| 11167 | request.url = GURL(url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11168 | request.traffic_annotation = |
| 11169 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11170 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11171 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11172 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11173 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11174 | |
| 11175 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11176 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11177 | } |
| 11178 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11179 | } // namespace |
| 11180 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11181 | TEST_F(HttpNetworkTransactionTest, GroupIdForDirectConnections) { |
| 11182 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11183 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11184 | "", // unused |
| 11185 | "http://www.example.org/direct", |
| 11186 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11187 | ClientSocketPool::SocketType::kHttp, |
| 11188 | false /* privacy_mode */), |
| 11189 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11190 | }, |
| 11191 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11192 | "", // unused |
| 11193 | "http://[2001:1418:13:1::25]/direct", |
| 11194 | ClientSocketPool::GroupId(HostPortPair("2001:1418:13:1::25", 80), |
| 11195 | ClientSocketPool::SocketType::kHttp, |
| 11196 | false /* privacy_mode */), |
| 11197 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11198 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11199 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11200 | // SSL Tests |
| 11201 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11202 | "", // unused |
| 11203 | "https://www.example.org/direct_ssl", |
| 11204 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11205 | ClientSocketPool::SocketType::kSsl, |
| 11206 | false /* privacy_mode */), |
| 11207 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11208 | }, |
| 11209 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11210 | "", // unused |
| 11211 | "https://[2001:1418:13:1::25]/direct", |
| 11212 | ClientSocketPool::GroupId(HostPortPair("2001:1418:13:1::25", 443), |
| 11213 | ClientSocketPool::SocketType::kSsl, |
| 11214 | false /* privacy_mode */), |
| 11215 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11216 | }, |
| 11217 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11218 | "", // unused |
| 11219 | "https://host.with.alternate/direct", |
| 11220 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11221 | ClientSocketPool::SocketType::kSsl, |
| 11222 | false /* privacy_mode */), |
| 11223 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11224 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11225 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11226 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11227 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11228 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11229 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11230 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11231 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11232 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11233 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11234 | HttpNetworkSessionPeer peer(session.get()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11235 | CaptureGroupIdTransportSocketPool* transport_conn_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 11236 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11237 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11238 | mock_pool_manager->SetSocketPool(ProxyServer::Direct(), |
| 11239 | base::WrapUnique(transport_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11240 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11241 | |
| 11242 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11243 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11244 | EXPECT_EQ(tests[i].expected_group_id, |
| 11245 | transport_conn_pool->last_group_id_received()); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 11246 | EXPECT_TRUE(transport_conn_pool->socket_requested()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11247 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11248 | } |
| 11249 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11250 | TEST_F(HttpNetworkTransactionTest, GroupIdForHTTPProxyConnections) { |
| 11251 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11252 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11253 | "http_proxy", |
| 11254 | "http://www.example.org/http_proxy_normal", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11255 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11256 | ClientSocketPool::SocketType::kHttp, |
| 11257 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11258 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11259 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11260 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11261 | // SSL Tests |
| 11262 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11263 | "http_proxy", |
| 11264 | "https://www.example.org/http_connect_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11265 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11266 | ClientSocketPool::SocketType::kSsl, |
| 11267 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11268 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11269 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11270 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11271 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11272 | "http_proxy", |
| 11273 | "https://host.with.alternate/direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11274 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11275 | ClientSocketPool::SocketType::kSsl, |
| 11276 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11277 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11278 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 11279 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11280 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11281 | "http_proxy", |
| 11282 | "ftp://ftp.google.com/http_proxy_normal", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11283 | ClientSocketPool::GroupId(HostPortPair("ftp.google.com", 21), |
| 11284 | ClientSocketPool::SocketType::kFtp, |
| 11285 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11286 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11287 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11288 | }; |
| 11289 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11290 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11291 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11292 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11293 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11294 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11295 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11296 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11297 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11298 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11299 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11300 | HostPortPair("http_proxy", 80)); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11301 | CaptureGroupIdTransportSocketPool* http_proxy_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 11302 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11303 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11304 | mock_pool_manager->SetSocketPool(proxy_server, |
| 11305 | base::WrapUnique(http_proxy_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11306 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11307 | |
| 11308 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11309 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11310 | EXPECT_EQ(tests[i].expected_group_id, |
| 11311 | http_proxy_pool->last_group_id_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11312 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11313 | } |
| 11314 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11315 | TEST_F(HttpNetworkTransactionTest, GroupIdForSOCKSConnections) { |
| 11316 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11317 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11318 | "socks4://socks_proxy:1080", |
| 11319 | "http://www.example.org/socks4_direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11320 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11321 | ClientSocketPool::SocketType::kHttp, |
| 11322 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11323 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11324 | }, |
| 11325 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11326 | "socks5://socks_proxy:1080", |
| 11327 | "http://www.example.org/socks5_direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11328 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11329 | ClientSocketPool::SocketType::kHttp, |
| 11330 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11331 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11332 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11333 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11334 | // SSL Tests |
| 11335 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11336 | "socks4://socks_proxy:1080", |
| 11337 | "https://www.example.org/socks4_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11338 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11339 | ClientSocketPool::SocketType::kSsl, |
| 11340 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11341 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11342 | }, |
| 11343 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11344 | "socks5://socks_proxy:1080", |
| 11345 | "https://www.example.org/socks5_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11346 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11347 | ClientSocketPool::SocketType::kSsl, |
| 11348 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11349 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11350 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11351 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11352 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11353 | "socks4://socks_proxy:1080", |
| 11354 | "https://host.with.alternate/direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11355 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11356 | ClientSocketPool::SocketType::kSsl, |
| 11357 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11358 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11359 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11360 | }; |
| 11361 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11362 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11363 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11364 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11365 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11366 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11367 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 11368 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11369 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11370 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11371 | ProxyServer proxy_server( |
| 11372 | ProxyServer::FromURI(tests[i].proxy_server, ProxyServer::SCHEME_HTTP)); |
| 11373 | ASSERT_TRUE(proxy_server.is_valid()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11374 | CaptureGroupIdTransportSocketPool* socks_conn_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 11375 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11376 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11377 | mock_pool_manager->SetSocketPool(proxy_server, |
| 11378 | base::WrapUnique(socks_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11379 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11380 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11381 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11382 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11383 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11384 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11385 | EXPECT_EQ(tests[i].expected_group_id, |
| 11386 | socks_conn_pool->last_group_id_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11387 | } |
| 11388 | } |
| 11389 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11390 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11391 | HttpRequestInfo request; |
| 11392 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11393 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11394 | request.traffic_annotation = |
| 11395 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11396 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11397 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11398 | "myproxy:70;foobar:80", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11399 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 11400 | // This simulates failure resolving all hostnames; that means we will fail |
| 11401 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11402 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11403 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11404 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11405 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11406 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11407 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11408 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11409 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11410 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11411 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11412 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11413 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11414 | } |
| 11415 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11416 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11417 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11418 | HttpRequestInfo request; |
| 11419 | request.method = "GET"; |
| 11420 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11421 | request.traffic_annotation = |
| 11422 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11423 | |
| 11424 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11425 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11426 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11427 | StaticSocketDataProvider data(base::span<MockRead>(), write_failure); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11428 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11429 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11430 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11431 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11432 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11433 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11434 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11435 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11436 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11437 | |
| 11438 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11439 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11440 | |
| 11441 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11442 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11443 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11444 | } |
| 11445 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11446 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11447 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11448 | HttpRequestInfo request; |
| 11449 | request.method = "GET"; |
| 11450 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11451 | request.traffic_annotation = |
| 11452 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11453 | |
| 11454 | MockRead data_reads[] = { |
| 11455 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11456 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11457 | }; |
| 11458 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11459 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11460 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11461 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11462 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11463 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11464 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11465 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11466 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11467 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11468 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11469 | |
| 11470 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11471 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11472 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11473 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11474 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11475 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11476 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11477 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11478 | |
| 11479 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11480 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11481 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11482 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11483 | |
| 11484 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11485 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11486 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11487 | } |
| 11488 | |
| 11489 | // Make sure that a dropped connection while draining the body for auth |
| 11490 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11491 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11492 | HttpRequestInfo request; |
| 11493 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11494 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11495 | request.traffic_annotation = |
| 11496 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11497 | |
| 11498 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11499 | MockWrite( |
| 11500 | "GET / HTTP/1.1\r\n" |
| 11501 | "Host: www.example.org\r\n" |
| 11502 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11503 | }; |
| 11504 | |
| 11505 | MockRead data_reads1[] = { |
| 11506 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 11507 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 11508 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11509 | MockRead("Content-Length: 14\r\n\r\n"), |
| 11510 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11511 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11512 | }; |
| 11513 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11514 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11515 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11516 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11517 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11518 | // be issuing -- the final header line contains the credentials. |
| 11519 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11520 | MockWrite( |
| 11521 | "GET / HTTP/1.1\r\n" |
| 11522 | "Host: www.example.org\r\n" |
| 11523 | "Connection: keep-alive\r\n" |
| 11524 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11525 | }; |
| 11526 | |
| 11527 | // Lastly, the server responds with the actual content. |
| 11528 | MockRead data_reads2[] = { |
| 11529 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11530 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11531 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11532 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11533 | }; |
| 11534 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11535 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11536 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11537 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11538 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11539 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11540 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11541 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11542 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11543 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11544 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11545 | |
| 11546 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11547 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11548 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11549 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11550 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11551 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11552 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11553 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11554 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11555 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11556 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11557 | |
| 11558 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11559 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11560 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11561 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11562 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11563 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11564 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11565 | } |
| 11566 | |
| 11567 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11568 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11569 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11570 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11571 | |
| 11572 | HttpRequestInfo request; |
| 11573 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11574 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11575 | request.traffic_annotation = |
| 11576 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11577 | |
| 11578 | MockRead proxy_reads[] = { |
| 11579 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11580 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11581 | }; |
| 11582 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11583 | StaticSocketDataProvider data(proxy_reads, base::span<MockWrite>()); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11584 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11585 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11586 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11587 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11588 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11589 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11590 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11591 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11592 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11593 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11594 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11595 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11596 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11597 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11598 | |
| 11599 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11600 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11601 | } |
| 11602 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11603 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11604 | HttpRequestInfo request; |
| 11605 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11606 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11607 | request.traffic_annotation = |
| 11608 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11609 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11610 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11611 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11612 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11613 | MockRead data_reads[] = { |
| 11614 | 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] | 11615 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11616 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11617 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11618 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11619 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11620 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11621 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11622 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11623 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11624 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11625 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11626 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11627 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11628 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11629 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11630 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11631 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11632 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11633 | |
| 11634 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11635 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11636 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11637 | } |
| 11638 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11639 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11640 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11641 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11642 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 11643 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 11644 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11645 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11646 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11647 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11648 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11649 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11650 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11651 | |
| 11652 | HttpRequestInfo request; |
| 11653 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11654 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11655 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11656 | request.traffic_annotation = |
| 11657 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11658 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11659 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11660 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11661 | |
| 11662 | MockRead data_reads[] = { |
| 11663 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 11664 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11665 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11666 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11667 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11668 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11669 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11670 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11671 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11672 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11673 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11674 | |
| 11675 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11676 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11677 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11678 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11679 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11680 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 11681 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11682 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11683 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11684 | } |
| 11685 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11686 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11687 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11688 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11689 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 11690 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 11691 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 11692 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 11693 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11694 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11695 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11696 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11697 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11698 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11699 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11700 | |
| 11701 | HttpRequestInfo request; |
| 11702 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11703 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11704 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11705 | request.traffic_annotation = |
| 11706 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11707 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 11708 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11709 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11710 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11711 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11712 | StaticSocketDataProvider data; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11713 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11714 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11715 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11716 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11717 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11718 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11719 | |
| 11720 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11721 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11722 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11723 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11724 | } |
| 11725 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11726 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11727 | class FakeUploadElementReader : public UploadElementReader { |
| 11728 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 11729 | FakeUploadElementReader() = default; |
| 11730 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11731 | |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11732 | CompletionOnceCallback TakeCallback() { return std::move(callback_); } |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11733 | |
| 11734 | // UploadElementReader overrides: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11735 | int Init(CompletionOnceCallback callback) override { |
| 11736 | callback_ = std::move(callback); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11737 | return ERR_IO_PENDING; |
| 11738 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11739 | uint64_t GetContentLength() const override { return 0; } |
| 11740 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11741 | int Read(IOBuffer* buf, |
| 11742 | int buf_length, |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11743 | CompletionOnceCallback callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11744 | return ERR_FAILED; |
| 11745 | } |
| 11746 | |
| 11747 | private: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11748 | CompletionOnceCallback callback_; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11749 | }; |
| 11750 | |
| 11751 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11752 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 11753 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11754 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11755 | |
| 11756 | HttpRequestInfo request; |
| 11757 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11758 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11759 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11760 | request.traffic_annotation = |
| 11761 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11762 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11763 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11764 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11765 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11766 | |
| 11767 | StaticSocketDataProvider data; |
| 11768 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11769 | |
| 11770 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11771 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11772 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 11773 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11774 | |
| 11775 | // Transaction is pending on request body initialization. |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11776 | CompletionOnceCallback init_callback = fake_reader->TakeCallback(); |
| 11777 | ASSERT_FALSE(init_callback.is_null()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11778 | |
| 11779 | // Return Init()'s result after the transaction gets destroyed. |
| 11780 | trans.reset(); |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11781 | std::move(init_callback).Run(OK); // Should not crash. |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11782 | } |
| 11783 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11784 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11785 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11786 | HttpRequestInfo request; |
| 11787 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11788 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11789 | request.traffic_annotation = |
| 11790 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11791 | |
| 11792 | // First transaction will request a resource and receive a Basic challenge |
| 11793 | // with realm="first_realm". |
| 11794 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11795 | MockWrite( |
| 11796 | "GET / HTTP/1.1\r\n" |
| 11797 | "Host: www.example.org\r\n" |
| 11798 | "Connection: keep-alive\r\n" |
| 11799 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11800 | }; |
| 11801 | MockRead data_reads1[] = { |
| 11802 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11803 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 11804 | "\r\n"), |
| 11805 | }; |
| 11806 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11807 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11808 | // for first_realm. The server will reject and provide a challenge with |
| 11809 | // second_realm. |
| 11810 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11811 | MockWrite( |
| 11812 | "GET / HTTP/1.1\r\n" |
| 11813 | "Host: www.example.org\r\n" |
| 11814 | "Connection: keep-alive\r\n" |
| 11815 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 11816 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11817 | }; |
| 11818 | MockRead data_reads2[] = { |
| 11819 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11820 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 11821 | "\r\n"), |
| 11822 | }; |
| 11823 | |
| 11824 | // This again fails, and goes back to first_realm. Make sure that the |
| 11825 | // entry is removed from cache. |
| 11826 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11827 | MockWrite( |
| 11828 | "GET / HTTP/1.1\r\n" |
| 11829 | "Host: www.example.org\r\n" |
| 11830 | "Connection: keep-alive\r\n" |
| 11831 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 11832 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11833 | }; |
| 11834 | MockRead data_reads3[] = { |
| 11835 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11836 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 11837 | "\r\n"), |
| 11838 | }; |
| 11839 | |
| 11840 | // Try one last time (with the correct password) and get the resource. |
| 11841 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11842 | MockWrite( |
| 11843 | "GET / HTTP/1.1\r\n" |
| 11844 | "Host: www.example.org\r\n" |
| 11845 | "Connection: keep-alive\r\n" |
| 11846 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 11847 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11848 | }; |
| 11849 | MockRead data_reads4[] = { |
| 11850 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11851 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11852 | "Content-Length: 5\r\n" |
| 11853 | "\r\n" |
| 11854 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11855 | }; |
| 11856 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11857 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 11858 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 11859 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
| 11860 | StaticSocketDataProvider data4(data_reads4, data_writes4); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11861 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 11862 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 11863 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 11864 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11865 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11866 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11867 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11868 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11869 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11870 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11871 | // Issue the first request with Authorize headers. There should be a |
| 11872 | // password prompt for first_realm waiting to be filled in after the |
| 11873 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11874 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11875 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11876 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11877 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11878 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11879 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11880 | base::Optional<AuthChallengeInfo> challenge = response->auth_challenge; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11881 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11882 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11883 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11884 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11885 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11886 | |
| 11887 | // Issue the second request with an incorrect password. There should be a |
| 11888 | // password prompt for second_realm waiting to be filled in after the |
| 11889 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11890 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11891 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 11892 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11893 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11894 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11895 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11896 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11897 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11898 | challenge = response->auth_challenge; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11899 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11900 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11901 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11902 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11903 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11904 | |
| 11905 | // Issue the third request with another incorrect password. There should be |
| 11906 | // a password prompt for first_realm waiting to be filled in. If the password |
| 11907 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 11908 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11909 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11910 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 11911 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11912 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11913 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11914 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11915 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11916 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11917 | challenge = response->auth_challenge; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11918 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11919 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11920 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11921 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11922 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11923 | |
| 11924 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11925 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11926 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 11927 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11928 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11929 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11930 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11931 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11932 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11933 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11934 | } |
| 11935 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11936 | // Regression test for https://crbug.com/754395. |
| 11937 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 11938 | MockRead data_reads[] = { |
| 11939 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11940 | MockRead(kAlternativeServiceHttpHeader), |
| 11941 | MockRead("\r\n"), |
| 11942 | MockRead("hello world"), |
| 11943 | MockRead(SYNCHRONOUS, OK), |
| 11944 | }; |
| 11945 | |
| 11946 | HttpRequestInfo request; |
| 11947 | request.method = "GET"; |
| 11948 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11949 | request.traffic_annotation = |
| 11950 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11951 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11952 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11953 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11954 | |
| 11955 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11956 | ssl.ssl_info.cert = |
| 11957 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11958 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 11959 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11960 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11961 | |
| 11962 | TestCompletionCallback callback; |
| 11963 | |
| 11964 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11965 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11966 | |
| 11967 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 11968 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11969 | |
| 11970 | url::SchemeHostPort test_server(request.url); |
| 11971 | HttpServerProperties* http_server_properties = |
| 11972 | session->http_server_properties(); |
| 11973 | EXPECT_TRUE( |
| 11974 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11975 | |
| 11976 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11977 | |
| 11978 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11979 | ASSERT_TRUE(response); |
| 11980 | ASSERT_TRUE(response->headers); |
| 11981 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11982 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11983 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 11984 | |
| 11985 | std::string response_data; |
| 11986 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11987 | EXPECT_EQ("hello world", response_data); |
| 11988 | |
| 11989 | EXPECT_TRUE( |
| 11990 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11991 | } |
| 11992 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11993 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11994 | MockRead data_reads[] = { |
| 11995 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11996 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11997 | MockRead("\r\n"), |
| 11998 | MockRead("hello world"), |
| 11999 | MockRead(SYNCHRONOUS, OK), |
| 12000 | }; |
| 12001 | |
| 12002 | HttpRequestInfo request; |
| 12003 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12004 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12005 | request.traffic_annotation = |
| 12006 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12007 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12008 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12009 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12010 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12011 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12012 | ssl.ssl_info.cert = |
| 12013 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12014 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12015 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12016 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12017 | TestCompletionCallback callback; |
| 12018 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12019 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12020 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12021 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12022 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12023 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12024 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12025 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12026 | HttpServerProperties* http_server_properties = |
| 12027 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12028 | EXPECT_TRUE( |
| 12029 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12030 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12031 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12032 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12033 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12034 | ASSERT_TRUE(response); |
| 12035 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12036 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12037 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12038 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12039 | |
| 12040 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12041 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12042 | EXPECT_EQ("hello world", response_data); |
| 12043 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12044 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 12045 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 12046 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 12047 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 12048 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12049 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12050 | } |
| 12051 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12052 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12053 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12054 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12055 | MockRead data_reads[] = { |
| 12056 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12057 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12058 | MockRead("\r\n"), |
| 12059 | MockRead("hello world"), |
| 12060 | MockRead(SYNCHRONOUS, OK), |
| 12061 | }; |
| 12062 | |
| 12063 | HttpRequestInfo request; |
| 12064 | request.method = "GET"; |
| 12065 | request.url = GURL("http://www.example.org/"); |
| 12066 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12067 | request.traffic_annotation = |
| 12068 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12069 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12070 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12071 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12072 | |
| 12073 | TestCompletionCallback callback; |
| 12074 | |
| 12075 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12076 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12077 | |
| 12078 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12079 | HttpServerProperties* http_server_properties = |
| 12080 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12081 | EXPECT_TRUE( |
| 12082 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12083 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12084 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12085 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12086 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12087 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12088 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12089 | ASSERT_TRUE(response); |
| 12090 | ASSERT_TRUE(response->headers); |
| 12091 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12092 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12093 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12094 | |
| 12095 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12096 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12097 | EXPECT_EQ("hello world", response_data); |
| 12098 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12099 | EXPECT_TRUE( |
| 12100 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12101 | } |
| 12102 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 12103 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12104 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12105 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12106 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 12107 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12108 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12109 | HttpRequestInfo request; |
| 12110 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12111 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12112 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12113 | request.traffic_annotation = |
| 12114 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12115 | |
| 12116 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12117 | StaticSocketDataProvider first_data; |
| 12118 | first_data.set_connect_data(mock_connect); |
| 12119 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12120 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12121 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12122 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12123 | |
| 12124 | MockRead data_reads[] = { |
| 12125 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12126 | MockRead(ASYNC, OK), |
| 12127 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12128 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12129 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12130 | |
| 12131 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12132 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12133 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12134 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12135 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 12136 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12137 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12138 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12139 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 12140 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12141 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12142 | TestCompletionCallback callback; |
| 12143 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12144 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12145 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12146 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12147 | } |
| 12148 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12149 | // Regression test for https://crbug.com/615497: |
| 12150 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12151 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12152 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12153 | HttpRequestInfo request; |
| 12154 | request.method = "GET"; |
| 12155 | request.url = GURL("http://www.example.org/"); |
| 12156 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12157 | request.traffic_annotation = |
| 12158 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12159 | |
| 12160 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12161 | StaticSocketDataProvider first_data; |
| 12162 | first_data.set_connect_data(mock_connect); |
| 12163 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 12164 | |
| 12165 | MockRead data_reads[] = { |
| 12166 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12167 | MockRead(ASYNC, OK), |
| 12168 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12169 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12170 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12171 | |
| 12172 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12173 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12174 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12175 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12176 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12177 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12178 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12179 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 12180 | |
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 | TestCompletionCallback callback; |
| 12183 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12184 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12185 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12186 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12187 | } |
| 12188 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12189 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12190 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12191 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12192 | HttpServerProperties* http_server_properties = |
| 12193 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12194 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12195 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12196 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12197 | http_server_properties->SetQuicAlternativeService( |
| 12198 | test_server, alternative_service, expiration, |
| 12199 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12200 | EXPECT_EQ( |
| 12201 | 1u, |
| 12202 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12203 | |
| 12204 | // Send a clear header. |
| 12205 | MockRead data_reads[] = { |
| 12206 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12207 | MockRead("Alt-Svc: clear\r\n"), |
| 12208 | MockRead("\r\n"), |
| 12209 | MockRead("hello world"), |
| 12210 | MockRead(SYNCHRONOUS, OK), |
| 12211 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12212 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12213 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12214 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12215 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12216 | ssl.ssl_info.cert = |
| 12217 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12218 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12219 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12220 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12221 | HttpRequestInfo request; |
| 12222 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12223 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12224 | request.traffic_annotation = |
| 12225 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12226 | |
| 12227 | TestCompletionCallback callback; |
| 12228 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12229 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12230 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12231 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12232 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12233 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12234 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12235 | ASSERT_TRUE(response); |
| 12236 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12237 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12238 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12239 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12240 | |
| 12241 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12242 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12243 | EXPECT_EQ("hello world", response_data); |
| 12244 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12245 | EXPECT_TRUE( |
| 12246 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12247 | } |
| 12248 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12249 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12250 | MockRead data_reads[] = { |
| 12251 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12252 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 12253 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12254 | MockRead("hello world"), |
| 12255 | MockRead(SYNCHRONOUS, OK), |
| 12256 | }; |
| 12257 | |
| 12258 | HttpRequestInfo request; |
| 12259 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12260 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12261 | request.traffic_annotation = |
| 12262 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12263 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12264 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12265 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12266 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12267 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12268 | ssl.ssl_info.cert = |
| 12269 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12270 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12271 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12272 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12273 | TestCompletionCallback callback; |
| 12274 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12275 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12276 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12277 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12278 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12279 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12280 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12281 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12282 | HttpServerProperties* http_server_properties = |
| 12283 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12284 | EXPECT_TRUE( |
| 12285 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12286 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12287 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12288 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12289 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12290 | ASSERT_TRUE(response); |
| 12291 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12292 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12293 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12294 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12295 | |
| 12296 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12297 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12298 | EXPECT_EQ("hello world", response_data); |
| 12299 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12300 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 12301 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 12302 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 12303 | |
| 12304 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 12305 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12306 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12307 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 12308 | 1234); |
| 12309 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12310 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12311 | } |
| 12312 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12313 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12314 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12315 | HostPortPair alternative("alternative.example.org", 443); |
| 12316 | std::string origin_url = "https://origin.example.org:443"; |
| 12317 | std::string alternative_url = "https://alternative.example.org:443"; |
| 12318 | |
| 12319 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12320 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12321 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12322 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12323 | |
| 12324 | // HTTP/1.1 data for request. |
| 12325 | MockWrite http_writes[] = { |
| 12326 | MockWrite("GET / HTTP/1.1\r\n" |
| 12327 | "Host: alternative.example.org\r\n" |
| 12328 | "Connection: keep-alive\r\n\r\n"), |
| 12329 | }; |
| 12330 | |
| 12331 | MockRead http_reads[] = { |
| 12332 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12333 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12334 | "Content-Length: 40\r\n\r\n" |
| 12335 | "first HTTP/1.1 response from alternative"), |
| 12336 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12337 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12338 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12339 | |
| 12340 | StaticSocketDataProvider data_refused; |
| 12341 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12342 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12343 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12344 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12345 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12346 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12347 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12348 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12349 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12350 | http_server_properties->SetQuicAlternativeService( |
| 12351 | server, alternative_service, expiration, |
| 12352 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12353 | // Mark the QUIC alternative service as broken. |
| 12354 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 12355 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12356 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12357 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12358 | request.method = "GET"; |
| 12359 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12360 | request.traffic_annotation = |
| 12361 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12362 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12363 | TestCompletionCallback callback; |
| 12364 | NetErrorDetails details; |
| 12365 | EXPECT_FALSE(details.quic_broken); |
| 12366 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12367 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12368 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12369 | EXPECT_TRUE(details.quic_broken); |
| 12370 | } |
| 12371 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12372 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12373 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12374 | HostPortPair alternative1("alternative1.example.org", 443); |
| 12375 | HostPortPair alternative2("alternative2.example.org", 443); |
| 12376 | std::string origin_url = "https://origin.example.org:443"; |
| 12377 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 12378 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 12379 | |
| 12380 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 12381 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12382 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12383 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12384 | |
| 12385 | // HTTP/1.1 data for request. |
| 12386 | MockWrite http_writes[] = { |
| 12387 | MockWrite("GET / HTTP/1.1\r\n" |
| 12388 | "Host: alternative1.example.org\r\n" |
| 12389 | "Connection: keep-alive\r\n\r\n"), |
| 12390 | }; |
| 12391 | |
| 12392 | MockRead http_reads[] = { |
| 12393 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12394 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12395 | "Content-Length: 40\r\n\r\n" |
| 12396 | "first HTTP/1.1 response from alternative1"), |
| 12397 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12398 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12399 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12400 | |
| 12401 | StaticSocketDataProvider data_refused; |
| 12402 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12403 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12404 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12405 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12406 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12407 | session->http_server_properties(); |
| 12408 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12409 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12410 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 12411 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 12412 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12413 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12414 | alternative_service_info_vector.push_back( |
| 12415 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12416 | alternative_service1, expiration, |
| 12417 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12418 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12419 | alternative_service_info_vector.push_back( |
| 12420 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12421 | alternative_service2, expiration, |
| 12422 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12423 | |
| 12424 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12425 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12426 | |
| 12427 | // Mark one of the QUIC alternative service as broken. |
| 12428 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12429 | EXPECT_EQ(2u, |
| 12430 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12431 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12432 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12433 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12434 | request.method = "GET"; |
| 12435 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12436 | request.traffic_annotation = |
| 12437 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12438 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12439 | TestCompletionCallback callback; |
| 12440 | NetErrorDetails details; |
| 12441 | EXPECT_FALSE(details.quic_broken); |
| 12442 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12443 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12444 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12445 | EXPECT_FALSE(details.quic_broken); |
| 12446 | } |
| 12447 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12448 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12449 | HttpRequestInfo request; |
| 12450 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12451 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12452 | request.traffic_annotation = |
| 12453 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12454 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12455 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12456 | StaticSocketDataProvider first_data; |
| 12457 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12458 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12459 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12460 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12461 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12462 | |
| 12463 | MockRead data_reads[] = { |
| 12464 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12465 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12466 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12467 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12468 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12469 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12470 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12471 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12472 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12473 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12474 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12475 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12476 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 12477 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12478 | // Port is ignored by MockConnect anyway. |
| 12479 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12480 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12481 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12482 | http_server_properties->SetHttp2AlternativeService( |
| 12483 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12484 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12485 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12486 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12487 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12488 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12489 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12490 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12491 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12492 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12493 | ASSERT_TRUE(response); |
| 12494 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12495 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12496 | |
| 12497 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12498 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12499 | EXPECT_EQ("hello world", response_data); |
| 12500 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12501 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 12502 | http_server_properties->GetAlternativeServiceInfos(server); |
| 12503 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 12504 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12505 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12506 | EXPECT_TRUE( |
| 12507 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12508 | } |
| 12509 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12510 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12511 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12512 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12513 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12514 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12515 | HttpRequestInfo restricted_port_request; |
| 12516 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12517 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12518 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12519 | restricted_port_request.traffic_annotation = |
| 12520 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12521 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12522 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12523 | StaticSocketDataProvider first_data; |
| 12524 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12525 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12526 | |
| 12527 | MockRead data_reads[] = { |
| 12528 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12529 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12530 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12531 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12532 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12533 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12534 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12535 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12536 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12537 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12538 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12539 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12540 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12541 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12542 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12543 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12544 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12545 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12546 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12547 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12548 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12549 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12550 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12551 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12552 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12553 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12554 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12555 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12556 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12557 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12558 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12559 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12560 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 12561 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 12562 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12563 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12564 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12565 | |
| 12566 | HttpRequestInfo restricted_port_request; |
| 12567 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12568 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12569 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12570 | restricted_port_request.traffic_annotation = |
| 12571 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12572 | |
| 12573 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12574 | StaticSocketDataProvider first_data; |
| 12575 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12576 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12577 | |
| 12578 | MockRead data_reads[] = { |
| 12579 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12580 | MockRead("hello world"), |
| 12581 | MockRead(ASYNC, OK), |
| 12582 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12583 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12584 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12585 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12586 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12587 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12588 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12589 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12590 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12591 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12592 | session->http_server_properties(); |
| 12593 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12594 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12595 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12596 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12597 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12598 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12599 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12600 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12601 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12602 | TestCompletionCallback callback; |
| 12603 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12604 | EXPECT_EQ(ERR_IO_PENDING, |
| 12605 | trans.Start(&restricted_port_request, callback.callback(), |
| 12606 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12607 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12608 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12609 | } |
| 12610 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12611 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12612 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12613 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12614 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12615 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12616 | HttpRequestInfo restricted_port_request; |
| 12617 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12618 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12619 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12620 | restricted_port_request.traffic_annotation = |
| 12621 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12622 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12623 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12624 | StaticSocketDataProvider first_data; |
| 12625 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12626 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12627 | |
| 12628 | MockRead data_reads[] = { |
| 12629 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12630 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12631 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12632 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12633 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12634 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12635 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12636 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12637 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12638 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12639 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12640 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12641 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12642 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12643 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12644 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12645 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12646 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12647 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12648 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12649 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12650 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12651 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12652 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12653 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12654 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12655 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12656 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12657 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12658 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12659 | } |
| 12660 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12661 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12662 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12663 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12664 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12665 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12666 | HttpRequestInfo unrestricted_port_request; |
| 12667 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12668 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12669 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12670 | unrestricted_port_request.traffic_annotation = |
| 12671 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12672 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12673 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12674 | StaticSocketDataProvider first_data; |
| 12675 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12676 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12677 | |
| 12678 | MockRead data_reads[] = { |
| 12679 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12680 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12681 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12682 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12683 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12684 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12685 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12686 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12687 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12688 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12689 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12690 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12691 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12692 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12693 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12694 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12695 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12696 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12697 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12698 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12699 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12700 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12701 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12702 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12703 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12704 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12705 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12706 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12707 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12708 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12709 | } |
| 12710 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12711 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12712 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12713 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12714 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12715 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12716 | HttpRequestInfo unrestricted_port_request; |
| 12717 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12718 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12719 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12720 | unrestricted_port_request.traffic_annotation = |
| 12721 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12722 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12723 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12724 | StaticSocketDataProvider first_data; |
| 12725 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12726 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12727 | |
| 12728 | MockRead data_reads[] = { |
| 12729 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12730 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12731 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12732 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12733 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12734 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12735 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12736 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12737 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12738 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12739 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12740 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12741 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12742 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 12743 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12744 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12745 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12746 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12747 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12748 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12749 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12750 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12751 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12752 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12753 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12754 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12755 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12756 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12757 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12758 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12759 | } |
| 12760 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12761 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
Xida Chen | 9bfe0b6 | 2018-04-24 19:52:21 | [diff] [blame] | 12762 | // to an unsafe port, and that we resume the second HttpStreamFactory::Job once |
| 12763 | // the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12764 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12765 | HttpRequestInfo request; |
| 12766 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12767 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12768 | request.traffic_annotation = |
| 12769 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12770 | |
| 12771 | // The alternate protocol request will error out before we attempt to connect, |
| 12772 | // so only the standard HTTP request will try to connect. |
| 12773 | MockRead data_reads[] = { |
| 12774 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12775 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12776 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12777 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12778 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12779 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12780 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12781 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12782 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12783 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12784 | session->http_server_properties(); |
| 12785 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12786 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12787 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12788 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12789 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12790 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12791 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12792 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12793 | TestCompletionCallback callback; |
| 12794 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12795 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12796 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12797 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12798 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12799 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12800 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12801 | ASSERT_TRUE(response); |
| 12802 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12803 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12804 | |
| 12805 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12806 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12807 | EXPECT_EQ("hello world", response_data); |
| 12808 | } |
| 12809 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12810 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12811 | HttpRequestInfo request; |
| 12812 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12813 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12814 | request.traffic_annotation = |
| 12815 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12816 | |
| 12817 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12818 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12819 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12820 | MockRead("\r\n"), |
| 12821 | MockRead("hello world"), |
| 12822 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12823 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12824 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12825 | StaticSocketDataProvider first_transaction(data_reads, |
| 12826 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12827 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12828 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12829 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12830 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12831 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12832 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12833 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12834 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12835 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12836 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12837 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 12838 | spdy::SpdySerializedFrame resp( |
| 12839 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12840 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12841 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12842 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12843 | }; |
| 12844 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12845 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12846 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12847 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12848 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12849 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12850 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 12851 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12852 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12853 | &hanging_non_alternate_protocol_socket); |
| 12854 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12855 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12856 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12857 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12858 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12859 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12860 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12861 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12862 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12863 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12864 | |
| 12865 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12866 | ASSERT_TRUE(response); |
| 12867 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12868 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12869 | |
| 12870 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12871 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12872 | EXPECT_EQ("hello world", response_data); |
| 12873 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12874 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12875 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12876 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12877 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12878 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12879 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12880 | |
| 12881 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12882 | ASSERT_TRUE(response); |
| 12883 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12884 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12885 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12886 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12887 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12888 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12889 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12890 | } |
| 12891 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12892 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12893 | HttpRequestInfo request; |
| 12894 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12895 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12896 | request.traffic_annotation = |
| 12897 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12898 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12899 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12900 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12901 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12902 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12903 | MockRead("\r\n"), |
| 12904 | MockRead("hello world"), |
| 12905 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12906 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12907 | }; |
| 12908 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12909 | StaticSocketDataProvider http11_data(data_reads, base::span<MockWrite>()); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12910 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12911 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12912 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12913 | ssl_http11.ssl_info.cert = |
| 12914 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12915 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12916 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 12917 | |
| 12918 | // Second transaction starts an alternative and a non-alternative Job. |
| 12919 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12920 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12921 | StaticSocketDataProvider hanging_socket1; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12922 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12923 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 12924 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12925 | StaticSocketDataProvider hanging_socket2; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12926 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 12927 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12928 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12929 | // Third transaction starts an alternative and a non-alternative job. |
| 12930 | // The non-alternative job hangs, but the alternative one succeeds. |
| 12931 | // The second transaction, still pending, binds to this socket. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12932 | spdy::SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12933 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12934 | spdy::SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12935 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12936 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12937 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12938 | }; |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 12939 | spdy::SpdySerializedFrame resp1( |
| 12940 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12941 | spdy::SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 12942 | spdy::SpdySerializedFrame resp2( |
| 12943 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12944 | spdy::SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12945 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12946 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 12947 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12948 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12949 | }; |
| 12950 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12951 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12952 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12953 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12954 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12955 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12956 | StaticSocketDataProvider hanging_socket3; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12957 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 12958 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12959 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12960 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12961 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12962 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12963 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12964 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12965 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12966 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12967 | |
| 12968 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12969 | ASSERT_TRUE(response); |
| 12970 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12971 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12972 | |
| 12973 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12974 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12975 | EXPECT_EQ("hello world", response_data); |
| 12976 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12977 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12978 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12979 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12980 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12981 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12982 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12983 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12984 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12985 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12986 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12987 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 12988 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12989 | |
| 12990 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12991 | ASSERT_TRUE(response); |
| 12992 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12993 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12994 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12995 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12996 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12997 | EXPECT_EQ("hello!", response_data); |
| 12998 | |
| 12999 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13000 | ASSERT_TRUE(response); |
| 13001 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13002 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13003 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13004 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13005 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13006 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13007 | } |
| 13008 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13009 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
Bence Béky | bcae3709 | 2018-06-12 04:18:53 | [diff] [blame] | 13010 | session_deps_.host_resolver->set_synchronous_mode(true); |
| 13011 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13012 | HttpRequestInfo request; |
| 13013 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13014 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13015 | request.traffic_annotation = |
| 13016 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13017 | |
| 13018 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13019 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13020 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13021 | MockRead("\r\n"), |
| 13022 | MockRead("hello world"), |
| 13023 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13024 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13025 | }; |
| 13026 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13027 | StaticSocketDataProvider first_transaction(data_reads, |
| 13028 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13029 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13030 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13031 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 13032 | ssl.ssl_info.cert = |
| 13033 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 13034 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13035 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13036 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13037 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13038 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13039 | hanging_alternate_protocol_socket.set_connect_data( |
| 13040 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13041 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13042 | &hanging_alternate_protocol_socket); |
| 13043 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13044 | // 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] | 13045 | StaticSocketDataProvider second_transaction(data_reads, |
| 13046 | base::span<MockWrite>()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13047 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13048 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13049 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13050 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13051 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13052 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13053 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13054 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13055 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13056 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13057 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13058 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13059 | |
| 13060 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13061 | ASSERT_TRUE(response); |
| 13062 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13063 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13064 | |
| 13065 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13066 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13067 | EXPECT_EQ("hello world", response_data); |
| 13068 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13069 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13070 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13071 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13072 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13073 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13074 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13075 | |
| 13076 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13077 | ASSERT_TRUE(response); |
| 13078 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13079 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13080 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13081 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13082 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13083 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13084 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13085 | } |
| 13086 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13087 | // Test that proxy is resolved using the origin url, |
| 13088 | // regardless of the alternative server. |
| 13089 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 13090 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 13091 | ProxyConfig proxy_config; |
| 13092 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 13093 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13094 | auto proxy_config_service = std::make_unique<ProxyConfigServiceFixed>( |
| 13095 | ProxyConfigWithAnnotation(proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13096 | |
| 13097 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13098 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13099 | &capturing_proxy_resolver); |
| 13100 | |
| 13101 | TestNetLog net_log; |
| 13102 | |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 13103 | session_deps_.proxy_resolution_service = |
| 13104 | std::make_unique<ProxyResolutionService>( |
| 13105 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 13106 | &net_log); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13107 | |
| 13108 | session_deps_.net_log = &net_log; |
| 13109 | |
| 13110 | // Configure alternative service with a hostname that is not bypassed by the |
| 13111 | // proxy. |
| 13112 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13113 | HttpServerProperties* http_server_properties = |
| 13114 | session->http_server_properties(); |
| 13115 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13116 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13117 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13118 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13119 | http_server_properties->SetHttp2AlternativeService( |
| 13120 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13121 | |
| 13122 | // Non-alternative job should hang. |
| 13123 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13124 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13125 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 13126 | session_deps_.socket_factory->AddSocketDataProvider( |
| 13127 | &hanging_alternate_protocol_socket); |
| 13128 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13129 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13130 | |
| 13131 | HttpRequestInfo request; |
| 13132 | request.method = "GET"; |
| 13133 | request.url = GURL("https://www.example.org/"); |
| 13134 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13135 | request.traffic_annotation = |
| 13136 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13137 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13138 | spdy::SpdySerializedFrame req( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13139 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 13140 | |
| 13141 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 13142 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13143 | spdy::SpdySerializedFrame resp( |
| 13144 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13145 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13146 | MockRead spdy_reads[] = { |
| 13147 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 13148 | }; |
| 13149 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13150 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13151 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 13152 | |
| 13153 | TestCompletionCallback callback; |
| 13154 | |
| 13155 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13156 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13157 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13158 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 13159 | |
| 13160 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 13161 | ASSERT_TRUE(response); |
| 13162 | ASSERT_TRUE(response->headers); |
| 13163 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13164 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13165 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13166 | |
| 13167 | std::string response_data; |
| 13168 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 13169 | EXPECT_EQ("hello!", response_data); |
| 13170 | |
| 13171 | // Origin host bypasses proxy, no resolution should have happened. |
| 13172 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 13173 | } |
| 13174 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13175 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13176 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13177 | proxy_config.set_auto_detect(true); |
| 13178 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 13179 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13180 | CapturingProxyResolver capturing_proxy_resolver; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13181 | session_deps_.proxy_resolution_service = |
| 13182 | std::make_unique<ProxyResolutionService>( |
| 13183 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 13184 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 13185 | std::make_unique<CapturingProxyResolverFactory>( |
| 13186 | &capturing_proxy_resolver), |
| 13187 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13188 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13189 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13190 | |
| 13191 | HttpRequestInfo request; |
| 13192 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13193 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13194 | request.traffic_annotation = |
| 13195 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13196 | |
| 13197 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13198 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13199 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13200 | MockRead("\r\n"), |
| 13201 | MockRead("hello world"), |
| 13202 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13203 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13204 | }; |
| 13205 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13206 | StaticSocketDataProvider first_transaction(data_reads, |
| 13207 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13208 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13209 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13210 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13211 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13212 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13213 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13214 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13215 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13216 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13217 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13218 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13219 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13220 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13221 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13222 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13223 | }; |
| 13224 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13225 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 13226 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13227 | spdy::SpdySerializedFrame resp( |
| 13228 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13229 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13230 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13231 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 13232 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13233 | }; |
| 13234 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13235 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13236 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13237 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13238 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13239 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13240 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 13241 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13242 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13243 | &hanging_non_alternate_protocol_socket); |
| 13244 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13245 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13246 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13247 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13248 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13249 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13250 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13251 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13252 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13253 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 13254 | |
| 13255 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13256 | ASSERT_TRUE(response); |
| 13257 | ASSERT_TRUE(response->headers); |
| 13258 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 13259 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13260 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13261 | |
| 13262 | std::string response_data; |
| 13263 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 13264 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13265 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13266 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13267 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13268 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13269 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13270 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13271 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13272 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13273 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13274 | ASSERT_TRUE(response); |
| 13275 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13276 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13277 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13278 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13279 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13280 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13281 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13282 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 13283 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13284 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13285 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13286 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13287 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13288 | LoadTimingInfo load_timing_info; |
| 13289 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 13290 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13291 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13292 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13293 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13294 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 13295 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 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 | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13299 | request.traffic_annotation = |
| 13300 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [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(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13308 | }; |
| 13309 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13310 | StaticSocketDataProvider first_transaction(data_reads, |
| 13311 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13312 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13313 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13314 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13315 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13316 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13317 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13318 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13319 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13320 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13321 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13322 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13323 | spdy::SpdySerializedFrame resp( |
| 13324 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13325 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13326 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13327 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13328 | }; |
| 13329 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13330 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13331 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13332 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 13333 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13334 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13335 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13336 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13337 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13338 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13339 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13340 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13341 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13342 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13343 | |
| 13344 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13345 | ASSERT_TRUE(response); |
| 13346 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13347 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13348 | |
| 13349 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13350 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13351 | EXPECT_EQ("hello world", response_data); |
| 13352 | |
| 13353 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13354 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13355 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 13356 | PRIVACY_MODE_DISABLED, |
| 13357 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13358 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 13359 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 13360 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13361 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13362 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13363 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13364 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13365 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13366 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13367 | |
| 13368 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13369 | ASSERT_TRUE(response); |
| 13370 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13371 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13372 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13373 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13374 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13375 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13376 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13377 | } |
| 13378 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13379 | // GenerateAuthToken is a mighty big test. |
| 13380 | // It tests all permutation of GenerateAuthToken behavior: |
| 13381 | // - Synchronous and Asynchronous completion. |
| 13382 | // - OK or error on completion. |
| 13383 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 13384 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 13385 | // - Non-authenticating and authenticating backend. |
| 13386 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 13387 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13388 | // problems generating an auth token for an authenticating proxy, we don't |
| 13389 | // need to test all permutations of the backend server). |
| 13390 | // |
| 13391 | // The test proceeds by going over each of the configuration cases, and |
| 13392 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 13393 | // specifies both the configuration for the test as well as the expectations |
| 13394 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13395 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13396 | static const char kServer[] = "http://www.example.com"; |
| 13397 | static const char kSecureServer[] = "https://www.example.com"; |
| 13398 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13399 | |
| 13400 | enum AuthTiming { |
| 13401 | AUTH_NONE, |
| 13402 | AUTH_SYNC, |
| 13403 | AUTH_ASYNC, |
| 13404 | }; |
| 13405 | |
| 13406 | const MockWrite kGet( |
| 13407 | "GET / HTTP/1.1\r\n" |
| 13408 | "Host: www.example.com\r\n" |
| 13409 | "Connection: keep-alive\r\n\r\n"); |
| 13410 | const MockWrite kGetProxy( |
| 13411 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13412 | "Host: www.example.com\r\n" |
| 13413 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13414 | const MockWrite kGetAuth( |
| 13415 | "GET / HTTP/1.1\r\n" |
| 13416 | "Host: www.example.com\r\n" |
| 13417 | "Connection: keep-alive\r\n" |
| 13418 | "Authorization: auth_token\r\n\r\n"); |
| 13419 | const MockWrite kGetProxyAuth( |
| 13420 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13421 | "Host: www.example.com\r\n" |
| 13422 | "Proxy-Connection: keep-alive\r\n" |
| 13423 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13424 | const MockWrite kGetAuthThroughProxy( |
| 13425 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13426 | "Host: www.example.com\r\n" |
| 13427 | "Proxy-Connection: keep-alive\r\n" |
| 13428 | "Authorization: auth_token\r\n\r\n"); |
| 13429 | const MockWrite kGetAuthWithProxyAuth( |
| 13430 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13431 | "Host: www.example.com\r\n" |
| 13432 | "Proxy-Connection: keep-alive\r\n" |
| 13433 | "Proxy-Authorization: auth_token\r\n" |
| 13434 | "Authorization: auth_token\r\n\r\n"); |
| 13435 | const MockWrite kConnect( |
| 13436 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13437 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13438 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13439 | const MockWrite kConnectProxyAuth( |
| 13440 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13441 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13442 | "Proxy-Connection: keep-alive\r\n" |
| 13443 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13444 | |
| 13445 | const MockRead kSuccess( |
| 13446 | "HTTP/1.1 200 OK\r\n" |
| 13447 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13448 | "Content-Length: 3\r\n\r\n" |
| 13449 | "Yes"); |
| 13450 | const MockRead kFailure( |
| 13451 | "Should not be called."); |
| 13452 | const MockRead kServerChallenge( |
| 13453 | "HTTP/1.1 401 Unauthorized\r\n" |
| 13454 | "WWW-Authenticate: Mock realm=server\r\n" |
| 13455 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13456 | "Content-Length: 14\r\n\r\n" |
| 13457 | "Unauthorized\r\n"); |
| 13458 | const MockRead kProxyChallenge( |
| 13459 | "HTTP/1.1 407 Unauthorized\r\n" |
| 13460 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 13461 | "Proxy-Connection: close\r\n" |
| 13462 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13463 | "Content-Length: 14\r\n\r\n" |
| 13464 | "Unauthorized\r\n"); |
| 13465 | const MockRead kProxyConnected( |
| 13466 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 13467 | |
| 13468 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 13469 | // no constructors, but the C++ compiler on Windows warns about |
| 13470 | // unspecified data in compound literals. So, moved to using constructors, |
| 13471 | // and TestRound's created with the default constructor should not be used. |
| 13472 | struct TestRound { |
| 13473 | TestRound() |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13474 | : expected_rv(ERR_UNEXPECTED), |
| 13475 | extra_write(nullptr), |
| 13476 | extra_read(nullptr) {} |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 13477 | TestRound(const MockWrite& write_arg, |
| 13478 | const MockRead& read_arg, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13479 | int expected_rv_arg) |
| 13480 | : write(write_arg), |
| 13481 | read(read_arg), |
| 13482 | expected_rv(expected_rv_arg), |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13483 | extra_write(nullptr), |
| 13484 | extra_read(nullptr) {} |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13485 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 13486 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 13487 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13488 | : write(write_arg), |
| 13489 | read(read_arg), |
| 13490 | expected_rv(expected_rv_arg), |
| 13491 | extra_write(extra_write_arg), |
| 13492 | extra_read(extra_read_arg) { |
| 13493 | } |
| 13494 | MockWrite write; |
| 13495 | MockRead read; |
| 13496 | int expected_rv; |
| 13497 | const MockWrite* extra_write; |
| 13498 | const MockRead* extra_read; |
| 13499 | }; |
| 13500 | |
| 13501 | static const int kNoSSL = 500; |
| 13502 | |
| 13503 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13504 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13505 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13506 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13507 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13508 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13509 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13510 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13511 | int num_auth_rounds; |
| 13512 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13513 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13514 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13515 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13516 | {__LINE__, |
| 13517 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13518 | AUTH_NONE, |
| 13519 | OK, |
| 13520 | kServer, |
| 13521 | AUTH_NONE, |
| 13522 | OK, |
| 13523 | 1, |
| 13524 | kNoSSL, |
| 13525 | {TestRound(kGet, kSuccess, OK)}}, |
| 13526 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13527 | {__LINE__, |
| 13528 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13529 | AUTH_NONE, |
| 13530 | OK, |
| 13531 | kServer, |
| 13532 | AUTH_SYNC, |
| 13533 | OK, |
| 13534 | 2, |
| 13535 | kNoSSL, |
| 13536 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13537 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13538 | {__LINE__, |
| 13539 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13540 | AUTH_NONE, |
| 13541 | OK, |
| 13542 | kServer, |
| 13543 | AUTH_SYNC, |
| 13544 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13545 | 3, |
| 13546 | kNoSSL, |
| 13547 | {TestRound(kGet, kServerChallenge, OK), |
| 13548 | TestRound(kGet, kServerChallenge, OK), |
| 13549 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13550 | {__LINE__, |
| 13551 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13552 | AUTH_NONE, |
| 13553 | OK, |
| 13554 | kServer, |
| 13555 | AUTH_SYNC, |
| 13556 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 13557 | 2, |
| 13558 | kNoSSL, |
| 13559 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13560 | {__LINE__, |
| 13561 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13562 | AUTH_NONE, |
| 13563 | OK, |
| 13564 | kServer, |
| 13565 | AUTH_SYNC, |
| 13566 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 13567 | 2, |
| 13568 | kNoSSL, |
| 13569 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13570 | {__LINE__, |
| 13571 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13572 | AUTH_SYNC, |
| 13573 | ERR_FAILED, |
| 13574 | kServer, |
| 13575 | AUTH_NONE, |
| 13576 | OK, |
| 13577 | 2, |
| 13578 | kNoSSL, |
| 13579 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13580 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13581 | {__LINE__, |
| 13582 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13583 | AUTH_ASYNC, |
| 13584 | ERR_FAILED, |
| 13585 | kServer, |
| 13586 | AUTH_NONE, |
| 13587 | OK, |
| 13588 | 2, |
| 13589 | kNoSSL, |
| 13590 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13591 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13592 | {__LINE__, |
| 13593 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13594 | AUTH_NONE, |
| 13595 | OK, |
| 13596 | kServer, |
| 13597 | AUTH_SYNC, |
| 13598 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13599 | 2, |
| 13600 | kNoSSL, |
| 13601 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13602 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13603 | {__LINE__, |
| 13604 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13605 | AUTH_NONE, |
| 13606 | OK, |
| 13607 | kServer, |
| 13608 | AUTH_ASYNC, |
| 13609 | ERR_FAILED, |
| 13610 | 2, |
| 13611 | kNoSSL, |
| 13612 | {TestRound(kGet, kServerChallenge, OK), |
| 13613 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13614 | {__LINE__, |
| 13615 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13616 | AUTH_NONE, |
| 13617 | OK, |
| 13618 | kServer, |
| 13619 | AUTH_ASYNC, |
| 13620 | OK, |
| 13621 | 2, |
| 13622 | kNoSSL, |
| 13623 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13624 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13625 | {__LINE__, |
| 13626 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13627 | AUTH_NONE, |
| 13628 | OK, |
| 13629 | kServer, |
| 13630 | AUTH_ASYNC, |
| 13631 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13632 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13633 | kNoSSL, |
| 13634 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13635 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 13636 | TestRound(kGet, kServerChallenge, OK), |
| 13637 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13638 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13639 | {__LINE__, |
| 13640 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13641 | AUTH_NONE, |
| 13642 | OK, |
| 13643 | kServer, |
| 13644 | AUTH_NONE, |
| 13645 | OK, |
| 13646 | 1, |
| 13647 | kNoSSL, |
| 13648 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 13649 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13650 | {__LINE__, |
| 13651 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13652 | AUTH_NONE, |
| 13653 | OK, |
| 13654 | kServer, |
| 13655 | AUTH_SYNC, |
| 13656 | OK, |
| 13657 | 2, |
| 13658 | kNoSSL, |
| 13659 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13660 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13661 | {__LINE__, |
| 13662 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13663 | AUTH_NONE, |
| 13664 | OK, |
| 13665 | kServer, |
| 13666 | AUTH_SYNC, |
| 13667 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13668 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13669 | kNoSSL, |
| 13670 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13671 | TestRound(kGetProxy, kServerChallenge, OK), |
| 13672 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13673 | {__LINE__, |
| 13674 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13675 | AUTH_NONE, |
| 13676 | OK, |
| 13677 | kServer, |
| 13678 | AUTH_ASYNC, |
| 13679 | OK, |
| 13680 | 2, |
| 13681 | kNoSSL, |
| 13682 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13683 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13684 | {__LINE__, |
| 13685 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13686 | AUTH_NONE, |
| 13687 | OK, |
| 13688 | kServer, |
| 13689 | AUTH_ASYNC, |
| 13690 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13691 | 2, |
| 13692 | kNoSSL, |
| 13693 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13694 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13695 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13696 | {__LINE__, |
| 13697 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13698 | AUTH_SYNC, |
| 13699 | OK, |
| 13700 | kServer, |
| 13701 | AUTH_NONE, |
| 13702 | OK, |
| 13703 | 2, |
| 13704 | kNoSSL, |
| 13705 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13706 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13707 | {__LINE__, |
| 13708 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13709 | AUTH_SYNC, |
| 13710 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13711 | kServer, |
| 13712 | AUTH_NONE, |
| 13713 | OK, |
| 13714 | 2, |
| 13715 | kNoSSL, |
| 13716 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13717 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13718 | {__LINE__, |
| 13719 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13720 | AUTH_ASYNC, |
| 13721 | OK, |
| 13722 | kServer, |
| 13723 | AUTH_NONE, |
| 13724 | OK, |
| 13725 | 2, |
| 13726 | kNoSSL, |
| 13727 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13728 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13729 | {__LINE__, |
| 13730 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13731 | AUTH_ASYNC, |
| 13732 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13733 | kServer, |
| 13734 | AUTH_NONE, |
| 13735 | OK, |
| 13736 | 2, |
| 13737 | kNoSSL, |
| 13738 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13739 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13740 | {__LINE__, |
| 13741 | kProxy, |
| 13742 | AUTH_ASYNC, |
| 13743 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13744 | kServer, |
| 13745 | AUTH_NONE, |
| 13746 | OK, |
| 13747 | 3, |
| 13748 | kNoSSL, |
| 13749 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13750 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13751 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13752 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13753 | {__LINE__, |
| 13754 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13755 | AUTH_SYNC, |
| 13756 | OK, |
| 13757 | kServer, |
| 13758 | AUTH_SYNC, |
| 13759 | OK, |
| 13760 | 3, |
| 13761 | kNoSSL, |
| 13762 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13763 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13764 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13765 | {__LINE__, |
| 13766 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13767 | AUTH_SYNC, |
| 13768 | OK, |
| 13769 | kServer, |
| 13770 | AUTH_SYNC, |
| 13771 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13772 | 3, |
| 13773 | kNoSSL, |
| 13774 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13775 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13776 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13777 | {__LINE__, |
| 13778 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13779 | AUTH_ASYNC, |
| 13780 | OK, |
| 13781 | kServer, |
| 13782 | AUTH_SYNC, |
| 13783 | OK, |
| 13784 | 3, |
| 13785 | kNoSSL, |
| 13786 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13787 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13788 | TestRound(kGetAuthWithProxyAuth, 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_ASYNC, |
| 13792 | OK, |
| 13793 | kServer, |
| 13794 | AUTH_SYNC, |
| 13795 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13796 | 3, |
| 13797 | kNoSSL, |
| 13798 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13799 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13800 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
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_ASYNC, |
| 13807 | OK, |
| 13808 | 3, |
| 13809 | kNoSSL, |
| 13810 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13811 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13812 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13813 | {__LINE__, |
| 13814 | kProxy, |
| 13815 | AUTH_SYNC, |
| 13816 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13817 | kServer, |
| 13818 | AUTH_ASYNC, |
| 13819 | OK, |
| 13820 | 4, |
| 13821 | kNoSSL, |
| 13822 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13823 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13824 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13825 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 13826 | {__LINE__, |
| 13827 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13828 | AUTH_SYNC, |
| 13829 | OK, |
| 13830 | kServer, |
| 13831 | AUTH_ASYNC, |
| 13832 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13833 | 3, |
| 13834 | kNoSSL, |
| 13835 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13836 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13837 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13838 | {__LINE__, |
| 13839 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13840 | AUTH_ASYNC, |
| 13841 | OK, |
| 13842 | kServer, |
| 13843 | AUTH_ASYNC, |
| 13844 | OK, |
| 13845 | 3, |
| 13846 | kNoSSL, |
| 13847 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13848 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13849 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13850 | {__LINE__, |
| 13851 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13852 | AUTH_ASYNC, |
| 13853 | OK, |
| 13854 | kServer, |
| 13855 | AUTH_ASYNC, |
| 13856 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13857 | 3, |
| 13858 | kNoSSL, |
| 13859 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13860 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13861 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13862 | {__LINE__, |
| 13863 | kProxy, |
| 13864 | AUTH_ASYNC, |
| 13865 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13866 | kServer, |
| 13867 | AUTH_ASYNC, |
| 13868 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13869 | 4, |
| 13870 | kNoSSL, |
| 13871 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13872 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13873 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13874 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13875 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13876 | {__LINE__, |
| 13877 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13878 | AUTH_NONE, |
| 13879 | OK, |
| 13880 | kSecureServer, |
| 13881 | AUTH_NONE, |
| 13882 | OK, |
| 13883 | 1, |
| 13884 | 0, |
| 13885 | {TestRound(kGet, kSuccess, OK)}}, |
| 13886 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13887 | {__LINE__, |
| 13888 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13889 | AUTH_NONE, |
| 13890 | OK, |
| 13891 | kSecureServer, |
| 13892 | AUTH_SYNC, |
| 13893 | OK, |
| 13894 | 2, |
| 13895 | 0, |
| 13896 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13897 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13898 | {__LINE__, |
| 13899 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13900 | AUTH_NONE, |
| 13901 | OK, |
| 13902 | kSecureServer, |
| 13903 | AUTH_SYNC, |
| 13904 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13905 | 2, |
| 13906 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13907 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13908 | {__LINE__, |
| 13909 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13910 | AUTH_NONE, |
| 13911 | OK, |
| 13912 | kSecureServer, |
| 13913 | AUTH_ASYNC, |
| 13914 | OK, |
| 13915 | 2, |
| 13916 | 0, |
| 13917 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13918 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13919 | {__LINE__, |
| 13920 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13921 | AUTH_NONE, |
| 13922 | OK, |
| 13923 | kSecureServer, |
| 13924 | AUTH_ASYNC, |
| 13925 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13926 | 2, |
| 13927 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13928 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13929 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13930 | {__LINE__, |
| 13931 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13932 | AUTH_NONE, |
| 13933 | OK, |
| 13934 | kSecureServer, |
| 13935 | AUTH_NONE, |
| 13936 | OK, |
| 13937 | 1, |
| 13938 | 0, |
| 13939 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 13940 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13941 | {__LINE__, |
| 13942 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13943 | AUTH_NONE, |
| 13944 | OK, |
| 13945 | kSecureServer, |
| 13946 | AUTH_SYNC, |
| 13947 | OK, |
| 13948 | 2, |
| 13949 | 0, |
| 13950 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13951 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13952 | {__LINE__, |
| 13953 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13954 | AUTH_NONE, |
| 13955 | OK, |
| 13956 | kSecureServer, |
| 13957 | AUTH_SYNC, |
| 13958 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13959 | 2, |
| 13960 | 0, |
| 13961 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13962 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13963 | {__LINE__, |
| 13964 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13965 | AUTH_NONE, |
| 13966 | OK, |
| 13967 | kSecureServer, |
| 13968 | AUTH_ASYNC, |
| 13969 | OK, |
| 13970 | 2, |
| 13971 | 0, |
| 13972 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13973 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13974 | {__LINE__, |
| 13975 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13976 | AUTH_NONE, |
| 13977 | OK, |
| 13978 | kSecureServer, |
| 13979 | AUTH_ASYNC, |
| 13980 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13981 | 2, |
| 13982 | 0, |
| 13983 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13984 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13985 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13986 | {__LINE__, |
| 13987 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13988 | AUTH_SYNC, |
| 13989 | OK, |
| 13990 | kSecureServer, |
| 13991 | AUTH_NONE, |
| 13992 | OK, |
| 13993 | 2, |
| 13994 | 1, |
| 13995 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13996 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13997 | {__LINE__, |
| 13998 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13999 | AUTH_SYNC, |
| 14000 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14001 | kSecureServer, |
| 14002 | AUTH_NONE, |
| 14003 | OK, |
| 14004 | 2, |
| 14005 | kNoSSL, |
| 14006 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14007 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14008 | {__LINE__, |
| 14009 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14010 | AUTH_SYNC, |
| 14011 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 14012 | kSecureServer, |
| 14013 | AUTH_NONE, |
| 14014 | OK, |
| 14015 | 2, |
| 14016 | kNoSSL, |
| 14017 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14018 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14019 | {__LINE__, |
| 14020 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14021 | AUTH_SYNC, |
| 14022 | ERR_UNEXPECTED, |
| 14023 | kSecureServer, |
| 14024 | AUTH_NONE, |
| 14025 | OK, |
| 14026 | 2, |
| 14027 | kNoSSL, |
| 14028 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14029 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14030 | {__LINE__, |
| 14031 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14032 | AUTH_ASYNC, |
| 14033 | OK, |
| 14034 | kSecureServer, |
| 14035 | AUTH_NONE, |
| 14036 | OK, |
| 14037 | 2, |
| 14038 | 1, |
| 14039 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14040 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14041 | {__LINE__, |
| 14042 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14043 | AUTH_ASYNC, |
| 14044 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14045 | kSecureServer, |
| 14046 | AUTH_NONE, |
| 14047 | OK, |
| 14048 | 2, |
| 14049 | kNoSSL, |
| 14050 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14051 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14052 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14053 | {__LINE__, |
| 14054 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14055 | AUTH_SYNC, |
| 14056 | OK, |
| 14057 | kSecureServer, |
| 14058 | AUTH_SYNC, |
| 14059 | OK, |
| 14060 | 3, |
| 14061 | 1, |
| 14062 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14063 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14064 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14065 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14066 | {__LINE__, |
| 14067 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14068 | AUTH_SYNC, |
| 14069 | OK, |
| 14070 | kSecureServer, |
| 14071 | AUTH_SYNC, |
| 14072 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14073 | 3, |
| 14074 | 1, |
| 14075 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14076 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14077 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14078 | TestRound(kGet, 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_ASYNC, |
| 14082 | OK, |
| 14083 | kSecureServer, |
| 14084 | AUTH_SYNC, |
| 14085 | OK, |
| 14086 | 3, |
| 14087 | 1, |
| 14088 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14089 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14090 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14091 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14092 | {__LINE__, |
| 14093 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14094 | AUTH_ASYNC, |
| 14095 | OK, |
| 14096 | kSecureServer, |
| 14097 | AUTH_SYNC, |
| 14098 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14099 | 3, |
| 14100 | 1, |
| 14101 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14102 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14103 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14104 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14105 | {__LINE__, |
| 14106 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14107 | AUTH_SYNC, |
| 14108 | OK, |
| 14109 | kSecureServer, |
| 14110 | AUTH_ASYNC, |
| 14111 | OK, |
| 14112 | 3, |
| 14113 | 1, |
| 14114 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14115 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14116 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14117 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14118 | {__LINE__, |
| 14119 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14120 | AUTH_SYNC, |
| 14121 | OK, |
| 14122 | kSecureServer, |
| 14123 | AUTH_ASYNC, |
| 14124 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14125 | 3, |
| 14126 | 1, |
| 14127 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14128 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14129 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14130 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14131 | {__LINE__, |
| 14132 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14133 | AUTH_ASYNC, |
| 14134 | OK, |
| 14135 | kSecureServer, |
| 14136 | AUTH_ASYNC, |
| 14137 | OK, |
| 14138 | 3, |
| 14139 | 1, |
| 14140 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14141 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14142 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14143 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14144 | {__LINE__, |
| 14145 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14146 | AUTH_ASYNC, |
| 14147 | OK, |
| 14148 | kSecureServer, |
| 14149 | AUTH_ASYNC, |
| 14150 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14151 | 3, |
| 14152 | 1, |
| 14153 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14154 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14155 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14156 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14157 | {__LINE__, |
| 14158 | kProxy, |
| 14159 | AUTH_ASYNC, |
| 14160 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14161 | kSecureServer, |
| 14162 | AUTH_ASYNC, |
| 14163 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14164 | 4, |
| 14165 | 2, |
| 14166 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14167 | TestRound(kConnect, kProxyChallenge, OK), |
| 14168 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14169 | &kServerChallenge), |
| 14170 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14171 | }; |
| 14172 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14173 | for (const auto& test_config : test_configs) { |
| 14174 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 14175 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14176 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14177 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14178 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14179 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14180 | |
| 14181 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14182 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14183 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14184 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14185 | std::string auth_challenge = "Mock realm=proxy"; |
| 14186 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14187 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14188 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14189 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14190 | empty_ssl_info, origin, |
| 14191 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14192 | auth_handler->SetGenerateExpectation( |
| 14193 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14194 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14195 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 14196 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14197 | } |
| 14198 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 14199 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14200 | std::string auth_challenge = "Mock realm=server"; |
| 14201 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14202 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14203 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14204 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14205 | empty_ssl_info, origin, |
| 14206 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14207 | auth_handler->SetGenerateExpectation( |
| 14208 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14209 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14210 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14211 | |
| 14212 | // The second handler always succeeds. It should only be used where there |
| 14213 | // are multiple auth sessions for server auth in the same network |
| 14214 | // transaction using the same auth scheme. |
| 14215 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14216 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14217 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 14218 | empty_ssl_info, origin, |
| 14219 | NetLogWithSource()); |
| 14220 | second_handler->SetGenerateExpectation(true, OK); |
| 14221 | auth_factory->AddMockHandler(second_handler.release(), |
| 14222 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14223 | } |
| 14224 | if (test_config.proxy_url) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14225 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14226 | ProxyResolutionService::CreateFixed(test_config.proxy_url, |
| 14227 | TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14228 | } else { |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14229 | session_deps_.proxy_resolution_service = |
| 14230 | ProxyResolutionService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14231 | } |
| 14232 | |
| 14233 | HttpRequestInfo request; |
| 14234 | request.method = "GET"; |
| 14235 | request.url = GURL(test_config.server_url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14236 | request.traffic_annotation = |
| 14237 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14238 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14239 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14240 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14241 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 14242 | |
| 14243 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 14244 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14245 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14246 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14247 | const TestRound& read_write_round = test_config.rounds[round]; |
| 14248 | |
| 14249 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14250 | mock_reads.back().push_back(read_write_round.read); |
| 14251 | mock_writes.back().push_back(read_write_round.write); |
| 14252 | |
| 14253 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 14254 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 14255 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14256 | mock_reads.push_back(std::vector<MockRead>()); |
| 14257 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14258 | } |
| 14259 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14260 | if (read_write_round.extra_read) { |
| 14261 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14262 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14263 | if (read_write_round.extra_write) { |
| 14264 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 14265 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14266 | |
| 14267 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14268 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14269 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14270 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14271 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14272 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14273 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14274 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14275 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14276 | mock_reads[i], mock_writes[i])); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14277 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 14278 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14279 | } |
| 14280 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 14281 | // Transaction must be created after DataProviders, so it's destroyed before |
| 14282 | // they are as well. |
| 14283 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 14284 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14285 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14286 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14287 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14288 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14289 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14290 | int rv; |
| 14291 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14292 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14293 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14294 | rv = trans.RestartWithAuth( |
| 14295 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14296 | } |
| 14297 | if (rv == ERR_IO_PENDING) |
| 14298 | rv = callback.WaitForResult(); |
| 14299 | |
| 14300 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14301 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14302 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 14303 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14304 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 14305 | continue; |
| 14306 | } |
| 14307 | if (round + 1 < test_config.num_auth_rounds) { |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14308 | EXPECT_TRUE(response->auth_challenge.has_value()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14309 | } else { |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14310 | EXPECT_FALSE(response->auth_challenge.has_value()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14311 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14312 | } |
| 14313 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 14314 | } |
| 14315 | } |
| 14316 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14317 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14318 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14319 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14320 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14321 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14322 | session_deps_.proxy_resolution_service = |
| 14323 | ProxyResolutionService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14324 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14325 | |
| 14326 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14327 | auth_handler->set_connection_based(true); |
| 14328 | std::string auth_challenge = "Mock realm=server"; |
| 14329 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14330 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14331 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14332 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14333 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14334 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14335 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14336 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14337 | int rv = OK; |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 14338 | const HttpResponseInfo* response = nullptr; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14339 | HttpRequestInfo request; |
| 14340 | request.method = "GET"; |
| 14341 | request.url = origin; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14342 | request.traffic_annotation = |
| 14343 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14344 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14345 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14346 | |
| 14347 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 14348 | // to validate that the TCP socket is not released to the pool between |
| 14349 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14350 | HttpNetworkSessionPeer session_peer(session.get()); |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 14351 | CommonConnectJobParams common_connect_job_params( |
| 14352 | session->CreateCommonConnectJobParams()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14353 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
Tarun Bansal | a763509 | 2019-02-20 10:00:59 | [diff] [blame] | 14354 | 50, // Max sockets for pool |
| 14355 | 1, // Max sockets per group |
| 14356 | base::TimeDelta::FromSeconds(10), // unused_idle_socket_timeout |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 14357 | &common_connect_job_params, session_deps_.ssl_config_service.get()); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14358 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 14359 | mock_pool_manager->SetSocketPool(ProxyServer::Direct(), |
| 14360 | base::WrapUnique(transport_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14361 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14362 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14363 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14364 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14365 | |
| 14366 | const MockWrite kGet( |
| 14367 | "GET / HTTP/1.1\r\n" |
| 14368 | "Host: www.example.com\r\n" |
| 14369 | "Connection: keep-alive\r\n\r\n"); |
| 14370 | const MockWrite kGetAuth( |
| 14371 | "GET / HTTP/1.1\r\n" |
| 14372 | "Host: www.example.com\r\n" |
| 14373 | "Connection: keep-alive\r\n" |
| 14374 | "Authorization: auth_token\r\n\r\n"); |
| 14375 | |
| 14376 | const MockRead kServerChallenge( |
| 14377 | "HTTP/1.1 401 Unauthorized\r\n" |
| 14378 | "WWW-Authenticate: Mock realm=server\r\n" |
| 14379 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14380 | "Content-Length: 14\r\n\r\n" |
| 14381 | "Unauthorized\r\n"); |
| 14382 | const MockRead kSuccess( |
| 14383 | "HTTP/1.1 200 OK\r\n" |
| 14384 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14385 | "Content-Length: 3\r\n\r\n" |
| 14386 | "Yes"); |
| 14387 | |
| 14388 | MockWrite writes[] = { |
| 14389 | // First round |
| 14390 | kGet, |
| 14391 | // Second round |
| 14392 | kGetAuth, |
| 14393 | // Third round |
| 14394 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14395 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14396 | kGetAuth, |
| 14397 | // Competing request |
| 14398 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14399 | }; |
| 14400 | MockRead reads[] = { |
| 14401 | // First round |
| 14402 | kServerChallenge, |
| 14403 | // Second round |
| 14404 | kServerChallenge, |
| 14405 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14406 | kServerChallenge, |
| 14407 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14408 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14409 | // Competing response |
| 14410 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14411 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14412 | StaticSocketDataProvider data_provider(reads, writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14413 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14414 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 14415 | const ClientSocketPool::GroupId kSocketGroup( |
| 14416 | HostPortPair("www.example.com", 80), ClientSocketPool::SocketType::kHttp, |
| 14417 | false /* privacy_mode */); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14418 | |
| 14419 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14420 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14421 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14422 | if (rv == ERR_IO_PENDING) |
| 14423 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14424 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14425 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14426 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14427 | EXPECT_TRUE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14428 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14429 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14430 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14431 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14432 | // In between rounds, another request comes in for the same domain. |
| 14433 | // It should not be able to grab the TCP socket that trans has already |
| 14434 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14435 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14436 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14437 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 14438 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14439 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14440 | // callback_compete.WaitForResult at this point would stall forever, |
| 14441 | // since the HttpNetworkTransaction does not release the request back to |
| 14442 | // the pool until after authentication completes. |
| 14443 | |
| 14444 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14445 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14446 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14447 | if (rv == ERR_IO_PENDING) |
| 14448 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14449 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14450 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14451 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14452 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14453 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14454 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14455 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14456 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14457 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14458 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14459 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14460 | if (rv == ERR_IO_PENDING) |
| 14461 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14462 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14463 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14464 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14465 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14466 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14467 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14468 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14469 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14470 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14471 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14472 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14473 | if (rv == ERR_IO_PENDING) |
| 14474 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14475 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14476 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14477 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14478 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14479 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14480 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14481 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 14482 | // auth handler should transition to a DONE state in concert with the remote |
| 14483 | // server. But that's not something we can test here with a mock handler. |
| 14484 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 14485 | auth_handler->state()); |
| 14486 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14487 | // Read the body since the fourth round was successful. This will also |
| 14488 | // release the socket back to the pool. |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 14489 | scoped_refptr<IOBufferWithSize> io_buf = |
| 14490 | base::MakeRefCounted<IOBufferWithSize>(50); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14491 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14492 | if (rv == ERR_IO_PENDING) |
| 14493 | rv = callback.WaitForResult(); |
| 14494 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14495 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14496 | EXPECT_EQ(0, rv); |
| 14497 | // There are still 0 idle sockets, since the trans_compete transaction |
| 14498 | // will be handed it immediately after trans releases it to the group. |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14499 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14500 | |
| 14501 | // The competing request can now finish. Wait for the headers and then |
| 14502 | // read the body. |
| 14503 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14504 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14505 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14506 | if (rv == ERR_IO_PENDING) |
| 14507 | rv = callback.WaitForResult(); |
| 14508 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14509 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14510 | EXPECT_EQ(0, rv); |
| 14511 | |
| 14512 | // Finally, the socket is released to the group. |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14513 | EXPECT_EQ(1u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14514 | } |
| 14515 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14516 | // This tests the case that a request is issued via http instead of spdy after |
| 14517 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14518 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14519 | HttpRequestInfo request; |
| 14520 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14521 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14522 | request.traffic_annotation = |
| 14523 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14524 | |
| 14525 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14526 | MockWrite( |
| 14527 | "GET / HTTP/1.1\r\n" |
| 14528 | "Host: www.example.org\r\n" |
| 14529 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14530 | }; |
| 14531 | |
| 14532 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14533 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 14534 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14535 | MockRead("\r\n"), |
| 14536 | MockRead("hello world"), |
| 14537 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14538 | }; |
| 14539 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14540 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14541 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14542 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14543 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14544 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14545 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14546 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14547 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14548 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14549 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14550 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14551 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14552 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14553 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14554 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14555 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14556 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14557 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14558 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14559 | ASSERT_TRUE(response); |
| 14560 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14561 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14562 | |
| 14563 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14564 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14565 | EXPECT_EQ("hello world", response_data); |
| 14566 | |
| 14567 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14568 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14569 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14570 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 14571 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 14572 | // immediate server closing of the socket. |
| 14573 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14574 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14575 | HttpRequestInfo request; |
| 14576 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14577 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14578 | request.traffic_annotation = |
| 14579 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14580 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14581 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14582 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14583 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14584 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14585 | spdy::SpdySerializedFrame req( |
| 14586 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14587 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14588 | |
| 14589 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14590 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14591 | }; |
| 14592 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14593 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14594 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14595 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14596 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14597 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14598 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14599 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14600 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14601 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14602 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14603 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14604 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14605 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14606 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 14607 | // it gets it. This is needed since the auth handler may get destroyed |
| 14608 | // before we get a chance to query it. |
| 14609 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 14610 | public: |
| 14611 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 14612 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 14613 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14614 | |
| 14615 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14616 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 14617 | const HttpRequestInfo* request, |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 14618 | CompletionOnceCallback callback, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14619 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14620 | *url_ = request->url; |
| 14621 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 14622 | credentials, request, std::move(callback), auth_token); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14623 | } |
| 14624 | |
| 14625 | private: |
| 14626 | GURL* url_; |
| 14627 | }; |
| 14628 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14629 | // Test that if we cancel the transaction as the connection is completing, that |
| 14630 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14631 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14632 | // Setup everything about the connection to complete synchronously, so that |
| 14633 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 14634 | // for is the callback from the HttpStreamRequest. |
| 14635 | // Then cancel the transaction. |
| 14636 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 14637 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14638 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14639 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 14640 | MockRead(SYNCHRONOUS, "hello world"), |
| 14641 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14642 | }; |
| 14643 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14644 | HttpRequestInfo request; |
| 14645 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14646 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14647 | request.traffic_annotation = |
| 14648 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14649 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14650 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14651 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14652 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14653 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14654 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14655 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14656 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14657 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14658 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14659 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14660 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14661 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14662 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14663 | trans.reset(); // Cancel the transaction here. |
| 14664 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14665 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 14666 | } |
| 14667 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14668 | // Test that if a transaction is cancelled after receiving the headers, the |
| 14669 | // stream is drained properly and added back to the socket pool. The main |
| 14670 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 14671 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 14672 | // deleted. |
| 14673 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14674 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14675 | MockRead data_reads[] = { |
| 14676 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 14677 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 14678 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 14679 | MockRead(ASYNC, "1"), |
| 14680 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 14681 | // HttpNetworkTransaction has been deleted. |
| 14682 | MockRead(ASYNC, "2"), |
| 14683 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 14684 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14685 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14686 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14687 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14688 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14689 | |
| 14690 | { |
| 14691 | HttpRequestInfo request; |
| 14692 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14693 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14694 | request.traffic_annotation = |
| 14695 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14696 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14697 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14698 | TestCompletionCallback callback; |
| 14699 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14700 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14701 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14702 | callback.WaitForResult(); |
| 14703 | |
| 14704 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14705 | ASSERT_TRUE(response); |
| 14706 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14707 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14708 | |
| 14709 | // The transaction and HttpRequestInfo are deleted. |
| 14710 | } |
| 14711 | |
| 14712 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14713 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14714 | |
| 14715 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14716 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14717 | } |
| 14718 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14719 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14720 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14721 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14722 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14723 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14724 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14725 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14726 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14727 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14728 | HttpRequestInfo request; |
| 14729 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14730 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14731 | request.traffic_annotation = |
| 14732 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14733 | |
| 14734 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14735 | MockWrite( |
| 14736 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 14737 | "Host: www.example.org\r\n" |
| 14738 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14739 | }; |
| 14740 | |
| 14741 | MockRead data_reads1[] = { |
| 14742 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14743 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14744 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14745 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14746 | }; |
| 14747 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14748 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14749 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14750 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14751 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14752 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14753 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14754 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14755 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14756 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 14757 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14758 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14759 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14760 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14761 | |
| 14762 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14763 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14764 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14765 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14766 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14767 | |
| 14768 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14769 | EXPECT_EQ(200, response->headers->response_code()); |
| 14770 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14771 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14772 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14773 | HostPortPair::FromString("myproxy:70")), |
| 14774 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14775 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14776 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14777 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14778 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14779 | |
| 14780 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14781 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14782 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14783 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14784 | } |
| 14785 | |
| 14786 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14787 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14788 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14789 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14790 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14791 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14792 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14793 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14794 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14795 | HttpRequestInfo request; |
| 14796 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14797 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14798 | request.traffic_annotation = |
| 14799 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14800 | |
| 14801 | // Since we have proxy, should try to establish tunnel. |
| 14802 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14803 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14804 | "Host: www.example.org:443\r\n" |
| 14805 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14806 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14807 | MockWrite("GET / HTTP/1.1\r\n" |
| 14808 | "Host: www.example.org\r\n" |
| 14809 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14810 | }; |
| 14811 | |
| 14812 | MockRead data_reads1[] = { |
| 14813 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14814 | |
| 14815 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14816 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14817 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14818 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14819 | }; |
| 14820 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14821 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14822 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14823 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14824 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14825 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14826 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14827 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14828 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14829 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14830 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14831 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 14832 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14833 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14834 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14835 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14836 | |
| 14837 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14838 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14839 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14840 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14841 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14842 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14843 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14844 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14845 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14846 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14847 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14848 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14849 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14850 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14851 | |
| 14852 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14853 | EXPECT_EQ(200, response->headers->response_code()); |
| 14854 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14855 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14856 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14857 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14858 | HostPortPair::FromString("myproxy:70")), |
| 14859 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14860 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14861 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14862 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14863 | |
| 14864 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14865 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14866 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14867 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14868 | } |
| 14869 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14870 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 14871 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14872 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14873 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14874 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14875 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14876 | BoundTestNetLog log; |
| 14877 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14878 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14879 | |
| 14880 | HttpRequestInfo request; |
| 14881 | request.method = "GET"; |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14882 | request.url = GURL("https://[::2]:443/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14883 | request.traffic_annotation = |
| 14884 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14885 | |
| 14886 | // Since we have proxy, should try to establish tunnel. |
| 14887 | MockWrite data_writes1[] = { |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14888 | MockWrite("CONNECT [::2]:443 HTTP/1.1\r\n" |
| 14889 | "Host: [::2]:443\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14890 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 14891 | |
| 14892 | MockWrite("GET / HTTP/1.1\r\n" |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14893 | "Host: [::2]\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14894 | "Connection: keep-alive\r\n\r\n"), |
| 14895 | }; |
| 14896 | |
| 14897 | MockRead data_reads1[] = { |
| 14898 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14899 | |
| 14900 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14901 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14902 | MockRead("Content-Length: 100\r\n\r\n"), |
| 14903 | MockRead(SYNCHRONOUS, OK), |
| 14904 | }; |
| 14905 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14906 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14907 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14908 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14909 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14910 | |
| 14911 | TestCompletionCallback callback1; |
| 14912 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14913 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14914 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14915 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14916 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14917 | |
| 14918 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14919 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14920 | TestNetLogEntry::List entries; |
| 14921 | log.GetEntries(&entries); |
| 14922 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14923 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14924 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14925 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14926 | entries, pos, |
| 14927 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14928 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14929 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14930 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14931 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14932 | |
| 14933 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14934 | EXPECT_EQ(200, response->headers->response_code()); |
| 14935 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14936 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14937 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14938 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14939 | HostPortPair::FromString("myproxy:70")), |
| 14940 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14941 | |
| 14942 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14943 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14944 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14945 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14946 | } |
| 14947 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14948 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 14949 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14950 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14951 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 14952 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14953 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14954 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14955 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14956 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14957 | HttpRequestInfo request; |
| 14958 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14959 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14960 | request.traffic_annotation = |
| 14961 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14962 | |
| 14963 | // Since we have proxy, should try to establish tunnel. |
| 14964 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14965 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14966 | "Host: www.example.org:443\r\n" |
| 14967 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14968 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14969 | MockWrite("GET / HTTP/1.1\r\n" |
| 14970 | "Host: www.example.org\r\n" |
| 14971 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14972 | }; |
| 14973 | |
| 14974 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14975 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14976 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14977 | }; |
| 14978 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14979 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14980 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14981 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14982 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14983 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14984 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14985 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14986 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14987 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14988 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14989 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14990 | |
| 14991 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14992 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14993 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14994 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14995 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14996 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14997 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14998 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14999 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15000 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 15001 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15002 | } |
| 15003 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15004 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15005 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15006 | spdy::SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15007 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15008 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15009 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15010 | spdy::SpdySerializedFrame resp( |
| 15011 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15012 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15013 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15014 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15015 | }; |
| 15016 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15017 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15018 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15019 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15020 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15021 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15022 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15023 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15024 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15025 | |
| 15026 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15027 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 15028 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 15029 | PRIVACY_MODE_DISABLED, |
| 15030 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 15031 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 15032 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15033 | |
| 15034 | HttpRequestInfo request; |
| 15035 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15036 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15037 | request.traffic_annotation = |
| 15038 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15039 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15040 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15041 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15042 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15043 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15044 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15045 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15046 | } |
| 15047 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15048 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15049 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 15050 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15051 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15052 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15053 | request_info.url = GURL("https://www.example.com/"); |
| 15054 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15055 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15056 | request_info.traffic_annotation = |
| 15057 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15058 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15059 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15060 | MockWrite data_writes[] = { |
| 15061 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15062 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15063 | StaticSocketDataProvider data(base::span<MockRead>(), data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15064 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15065 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15066 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15067 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15068 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15069 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15070 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15071 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15072 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15073 | rv = callback.WaitForResult(); |
| 15074 | ASSERT_EQ(error, rv); |
| 15075 | } |
| 15076 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15077 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15078 | // Just check a grab bag of cert errors. |
| 15079 | static const int kErrors[] = { |
| 15080 | ERR_CERT_COMMON_NAME_INVALID, |
| 15081 | ERR_CERT_AUTHORITY_INVALID, |
| 15082 | ERR_CERT_DATE_INVALID, |
| 15083 | }; |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 15084 | for (size_t i = 0; i < base::size(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15085 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 15086 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15087 | } |
| 15088 | } |
| 15089 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15090 | // Ensure that a client certificate is removed from the SSL client auth |
| 15091 | // cache when: |
| 15092 | // 1) No proxy is involved. |
| 15093 | // 2) TLS False Start is disabled. |
| 15094 | // 3) The initial TLS handshake requests a client certificate. |
| 15095 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15096 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15097 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15098 | request_info.url = GURL("https://www.example.com/"); |
| 15099 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15100 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15101 | request_info.traffic_annotation = |
| 15102 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15103 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15104 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15105 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15106 | |
| 15107 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 15108 | // CertificateRequest is received for the first time, the handshake will |
| 15109 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15110 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15111 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15112 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15113 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15114 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15115 | |
| 15116 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 15117 | // False Start is not being used, the result of the SSL handshake will be |
| 15118 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 15119 | // matches the result of a server sending a handshake_failure alert, |
| 15120 | // rather than a Finished message, because it requires a client |
| 15121 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15122 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15123 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15124 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15125 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15126 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15127 | |
| 15128 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 15129 | // connection to a server fails during an SSL handshake, |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15130 | // HttpNetworkTransaction will attempt to fallback to TLSv1.2 if the previous |
| 15131 | // connection was attempted with TLSv1.3. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15132 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15133 | // requiring a client certificate, this fallback handshake should also |
| 15134 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15135 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15136 | ssl_data3.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15137 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15138 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15139 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15140 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15141 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15142 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 15143 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 15144 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 15145 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15146 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15147 | // requiring a client certificate, this fallback handshake should also |
| 15148 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15149 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15150 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15151 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15152 | StaticSocketDataProvider data4; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15153 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15154 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15155 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15156 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15157 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15158 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15159 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15160 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15161 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15162 | |
| 15163 | // Complete the SSL handshake, which should abort due to requiring a |
| 15164 | // client certificate. |
| 15165 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15166 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15167 | |
| 15168 | // Indicate that no certificate should be supplied. From the perspective |
| 15169 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15170 | // certificate, so this is the same as supply a |
| 15171 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15172 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15173 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15174 | |
| 15175 | // Ensure the certificate was added to the client auth cache before |
| 15176 | // allowing the connection to continue restarting. |
| 15177 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15178 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15179 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15180 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15181 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15182 | |
| 15183 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15184 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15185 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15186 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15187 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15188 | |
| 15189 | // Ensure that the client certificate is removed from the cache on a |
| 15190 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15191 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15192 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15193 | } |
| 15194 | |
| 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 enabled. |
| 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_FalseStart) { |
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 | b5e433e6 | 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 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 15213 | // return successfully after reading up to the peer's Certificate message. |
| 15214 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 15215 | // enqueue application data to be sent in the same packet as the |
| 15216 | // ChangeCipherSpec and Finished messages. |
| 15217 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 15218 | // called, which expects to process the peer's ChangeCipherSpec and |
| 15219 | // Finished messages. If there was an error negotiating with the peer, |
| 15220 | // such as due to the peer requiring a client certificate when none was |
| 15221 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 15222 | // called. |
| 15223 | |
| 15224 | // Like the non-False Start case, when a client certificate is requested by |
| 15225 | // the peer, the handshake is aborted during the Connect() call. |
| 15226 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15227 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15228 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15229 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15230 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15231 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15232 | |
| 15233 | // When a client certificate is supplied, Connect() will not be aborted |
| 15234 | // when the peer requests the certificate. Instead, the handshake will |
| 15235 | // artificially succeed, allowing the caller to write the HTTP request to |
| 15236 | // the socket. The handshake messages are not processed until Read() is |
| 15237 | // called, which then detects that the handshake was aborted, due to the |
| 15238 | // peer sending a handshake_failure because it requires a client |
| 15239 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15240 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15241 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15242 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15243 | MockRead data2_reads[] = { |
| 15244 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15245 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15246 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15247 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15248 | |
| 15249 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15250 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 15251 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15252 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15253 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15254 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15255 | StaticSocketDataProvider data3(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15256 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15257 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15258 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 15259 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15260 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15261 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15262 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15263 | StaticSocketDataProvider data4(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15264 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15265 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15266 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15267 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15268 | ssl_data5.cert_request_info = cert_request.get(); |
| 15269 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15270 | StaticSocketDataProvider data5(data2_reads, base::span<MockWrite>()); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15271 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 15272 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15273 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15274 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15275 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15276 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15277 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15278 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15279 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15280 | |
| 15281 | // Complete the SSL handshake, which should abort due to requiring a |
| 15282 | // client certificate. |
| 15283 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15284 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15285 | |
| 15286 | // Indicate that no certificate should be supplied. From the perspective |
| 15287 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15288 | // certificate, so this is the same as supply a |
| 15289 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15290 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15291 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15292 | |
| 15293 | // Ensure the certificate was added to the client auth cache before |
| 15294 | // allowing the connection to continue restarting. |
| 15295 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15296 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15297 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15298 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15299 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15300 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15301 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15302 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15303 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15304 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15305 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15306 | |
| 15307 | // Ensure that the client certificate is removed from the cache on a |
| 15308 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15309 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15310 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15311 | } |
| 15312 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15313 | // Ensure that a client certificate is removed from the SSL client auth |
| 15314 | // cache when: |
| 15315 | // 1) An HTTPS proxy is involved. |
| 15316 | // 3) The HTTPS proxy requests a client certificate. |
| 15317 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 15318 | // proxy. |
| 15319 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 15320 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15321 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15322 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 15323 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15324 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15325 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15326 | |
| 15327 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15328 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15329 | |
| 15330 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 15331 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 15332 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 15333 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15334 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15335 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15336 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15337 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15338 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15339 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15340 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15341 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15342 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15343 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15344 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15345 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15346 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 15347 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15348 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15349 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15350 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15351 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15352 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15353 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15354 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15355 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15356 | requests[0].url = GURL("https://www.example.com/"); |
| 15357 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15358 | requests[0].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15359 | requests[0].traffic_annotation = |
| 15360 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15361 | |
| 15362 | requests[1].url = GURL("http://www.example.com/"); |
| 15363 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15364 | requests[1].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15365 | requests[1].traffic_annotation = |
| 15366 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15367 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 15368 | for (size_t i = 0; i < base::size(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15369 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15370 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15371 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15372 | |
| 15373 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15374 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15375 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15376 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15377 | |
| 15378 | // Complete the SSL handshake, which should abort due to requiring a |
| 15379 | // client certificate. |
| 15380 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15381 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15382 | |
| 15383 | // Indicate that no certificate should be supplied. From the perspective |
| 15384 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15385 | // certificate, so this is the same as supply a |
| 15386 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15387 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15388 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15389 | |
| 15390 | // Ensure the certificate was added to the client auth cache before |
| 15391 | // allowing the connection to continue restarting. |
| 15392 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15393 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15394 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15395 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15396 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15397 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 15398 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15399 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15400 | HostPortPair("www.example.com", 443), &client_cert, |
| 15401 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15402 | |
| 15403 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 15404 | // then consume ssl_data3, which should also fail. The result code is |
| 15405 | // checked against what ssl_data3 should return. |
| 15406 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15407 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15408 | |
| 15409 | // Now that the new handshake has failed, ensure that the client |
| 15410 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15411 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15412 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15413 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15414 | HostPortPair("www.example.com", 443), &client_cert, |
| 15415 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15416 | } |
| 15417 | } |
| 15418 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15419 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15420 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15421 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15422 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15423 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15424 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15425 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15426 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15427 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15428 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15429 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15430 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15431 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15432 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15433 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15434 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15435 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15436 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15437 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15438 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15439 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15440 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15441 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15442 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15443 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15444 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15445 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15446 | }; |
| 15447 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15448 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15449 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15450 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15451 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15452 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15453 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15454 | HttpRequestInfo request1; |
| 15455 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15456 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15457 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15458 | request1.traffic_annotation = |
| 15459 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15460 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15461 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15462 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15463 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15464 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15465 | |
| 15466 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15467 | ASSERT_TRUE(response); |
| 15468 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15469 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15470 | |
| 15471 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15472 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15473 | EXPECT_EQ("hello!", response_data); |
| 15474 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15475 | // Preload mail.example.com into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15476 | rv = session_deps_.host_resolver->LoadIntoCache( |
| 15477 | HostPortPair("mail.example.com", 443), base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15478 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15479 | |
| 15480 | HttpRequestInfo request2; |
| 15481 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15482 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15483 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15484 | request2.traffic_annotation = |
| 15485 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15486 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15487 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15488 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15489 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15490 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15491 | |
| 15492 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15493 | ASSERT_TRUE(response); |
| 15494 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15495 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15496 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15497 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15498 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15499 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15500 | } |
| 15501 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15502 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15503 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15504 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15505 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15506 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15507 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15508 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15509 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15510 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15511 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15512 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15513 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15514 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15515 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15516 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15517 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15518 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15519 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15520 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15521 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15522 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15523 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15524 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15525 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15526 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15527 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15528 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15529 | }; |
| 15530 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15531 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15532 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15533 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15534 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15535 | |
| 15536 | TestCompletionCallback callback; |
| 15537 | HttpRequestInfo request1; |
| 15538 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15539 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15540 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15541 | request1.traffic_annotation = |
| 15542 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15543 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15544 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15545 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15546 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15547 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15548 | |
| 15549 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15550 | ASSERT_TRUE(response); |
| 15551 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15552 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15553 | |
| 15554 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15555 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15556 | EXPECT_EQ("hello!", response_data); |
| 15557 | |
| 15558 | HttpRequestInfo request2; |
| 15559 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15560 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15561 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15562 | request2.traffic_annotation = |
| 15563 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15564 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15565 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15566 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15567 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15568 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15569 | |
| 15570 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15571 | ASSERT_TRUE(response); |
| 15572 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15573 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15574 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15575 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15576 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15577 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15578 | } |
| 15579 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15580 | // Regression test for https://crbug.com/546991. |
| 15581 | // The server might not be able to serve an IP pooled request, and might send a |
| 15582 | // 421 Misdirected Request response status to indicate this. |
| 15583 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 15584 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 15585 | // Two hosts resolve to the same IP address. |
| 15586 | const std::string ip_addr = "1.2.3.4"; |
| 15587 | IPAddress ip; |
| 15588 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 15589 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15590 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15591 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15592 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 15593 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 15594 | |
| 15595 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15596 | |
| 15597 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15598 | spdy::SpdySerializedFrame req1( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15599 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 15600 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15601 | spdy::SpdySerializedFrame req2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15602 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15603 | spdy::SpdySerializedFrame rst( |
| 15604 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15605 | MockWrite writes1[] = { |
| 15606 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 15607 | CreateMockWrite(rst, 6), |
| 15608 | }; |
| 15609 | |
| 15610 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15611 | spdy::SpdySerializedFrame resp1( |
| 15612 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15613 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15614 | spdy::SpdyHeaderBlock response_headers; |
| 15615 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 15616 | spdy::SpdySerializedFrame resp2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15617 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 15618 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 15619 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 15620 | |
| 15621 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15622 | SequencedSocketData data1(connect1, reads1, writes1); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15623 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15624 | |
| 15625 | AddSSLSocketData(); |
| 15626 | |
| 15627 | // Retry the second request on a second connection. |
| 15628 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15629 | spdy::SpdySerializedFrame req3( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15630 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 15631 | MockWrite writes2[] = { |
| 15632 | CreateMockWrite(req3, 0), |
| 15633 | }; |
| 15634 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15635 | spdy::SpdySerializedFrame resp3( |
| 15636 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15637 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15638 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 15639 | MockRead(ASYNC, 0, 3)}; |
| 15640 | |
| 15641 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15642 | SequencedSocketData data2(connect2, reads2, writes2); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15643 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15644 | |
| 15645 | AddSSLSocketData(); |
| 15646 | |
| 15647 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15648 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 15649 | HostPortPair("mail.example.com", 443), base::nullopt); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15650 | EXPECT_THAT(rv, IsOk()); |
| 15651 | |
| 15652 | HttpRequestInfo request1; |
| 15653 | request1.method = "GET"; |
| 15654 | request1.url = GURL("https://www.example.org/"); |
| 15655 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15656 | request1.traffic_annotation = |
| 15657 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15658 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15659 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15660 | TestCompletionCallback callback; |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15661 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 15662 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15663 | rv = callback.WaitForResult(); |
| 15664 | EXPECT_THAT(rv, IsOk()); |
| 15665 | |
| 15666 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 15667 | ASSERT_TRUE(response); |
| 15668 | ASSERT_TRUE(response->headers); |
| 15669 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15670 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15671 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15672 | std::string response_data; |
| 15673 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 15674 | EXPECT_EQ("hello!", response_data); |
| 15675 | |
| 15676 | HttpRequestInfo request2; |
| 15677 | request2.method = "GET"; |
| 15678 | request2.url = GURL("https://mail.example.org/"); |
| 15679 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15680 | request2.traffic_annotation = |
| 15681 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15682 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15683 | |
| 15684 | BoundTestNetLog log; |
| 15685 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 15686 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15687 | rv = callback.WaitForResult(); |
| 15688 | EXPECT_THAT(rv, IsOk()); |
| 15689 | |
| 15690 | response = trans2.GetResponseInfo(); |
| 15691 | ASSERT_TRUE(response); |
| 15692 | ASSERT_TRUE(response->headers); |
| 15693 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15694 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15695 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15696 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 15697 | EXPECT_EQ("hello!", response_data); |
| 15698 | |
| 15699 | TestNetLogEntry::List entries; |
| 15700 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15701 | ExpectLogContainsSomewhere( |
| 15702 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15703 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15704 | } |
| 15705 | |
| 15706 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 15707 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 15708 | // portions of the response. |
| 15709 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 15710 | // Two hosts resolve to the same IP address. |
| 15711 | const std::string ip_addr = "1.2.3.4"; |
| 15712 | IPAddress ip; |
| 15713 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 15714 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15715 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15716 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15717 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 15718 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 15719 | |
| 15720 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15721 | |
| 15722 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15723 | spdy::SpdySerializedFrame req1( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15724 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 15725 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15726 | spdy::SpdySerializedFrame req2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15727 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15728 | spdy::SpdySerializedFrame rst( |
| 15729 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15730 | MockWrite writes1[] = { |
| 15731 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 15732 | CreateMockWrite(rst, 6), |
| 15733 | }; |
| 15734 | |
| 15735 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15736 | spdy::SpdySerializedFrame resp1( |
| 15737 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15738 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15739 | spdy::SpdyHeaderBlock response_headers; |
| 15740 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 15741 | spdy::SpdySerializedFrame resp2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15742 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 15743 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 15744 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 15745 | |
| 15746 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15747 | SequencedSocketData data1(connect1, reads1, writes1); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15748 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15749 | |
| 15750 | AddSSLSocketData(); |
| 15751 | |
| 15752 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 15753 | // Retry again. |
| 15754 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15755 | spdy::SpdySerializedFrame req3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15756 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 15757 | MockWrite writes2[] = { |
| 15758 | CreateMockWrite(req3, 0), |
| 15759 | }; |
| 15760 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15761 | spdy::SpdySerializedFrame resp3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15762 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15763 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15764 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 15765 | MockRead(ASYNC, 0, 3)}; |
| 15766 | |
| 15767 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15768 | SequencedSocketData data2(connect2, reads2, writes2); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15769 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15770 | |
| 15771 | AddSSLSocketData(); |
| 15772 | |
| 15773 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15774 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 15775 | HostPortPair("mail.example.com", 443), base::nullopt); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15776 | EXPECT_THAT(rv, IsOk()); |
| 15777 | |
| 15778 | HttpRequestInfo request1; |
| 15779 | request1.method = "GET"; |
| 15780 | request1.url = GURL("https://www.example.org/"); |
| 15781 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15782 | request1.traffic_annotation = |
| 15783 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15784 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15785 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15786 | TestCompletionCallback callback; |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15787 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 15788 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15789 | rv = callback.WaitForResult(); |
| 15790 | EXPECT_THAT(rv, IsOk()); |
| 15791 | |
| 15792 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 15793 | ASSERT_TRUE(response); |
| 15794 | ASSERT_TRUE(response->headers); |
| 15795 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15796 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15797 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15798 | std::string response_data; |
| 15799 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 15800 | EXPECT_EQ("hello!", response_data); |
| 15801 | |
| 15802 | HttpRequestInfo request2; |
| 15803 | request2.method = "GET"; |
| 15804 | request2.url = GURL("https://mail.example.org/"); |
| 15805 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15806 | request2.traffic_annotation = |
| 15807 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15808 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15809 | |
| 15810 | BoundTestNetLog log; |
| 15811 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 15812 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15813 | rv = callback.WaitForResult(); |
| 15814 | EXPECT_THAT(rv, IsOk()); |
| 15815 | |
| 15816 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 15817 | // caller. |
| 15818 | response = trans2.GetResponseInfo(); |
| 15819 | ASSERT_TRUE(response); |
| 15820 | ASSERT_TRUE(response->headers); |
| 15821 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 15822 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15823 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15824 | EXPECT_TRUE(response->ssl_info.cert); |
| 15825 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 15826 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15827 | } |
| 15828 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15829 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 15830 | UseIPConnectionPoolingWithHostCacheExpiration) { |
Eric Orth | 1da75de | 2019-02-20 21:10:34 | [diff] [blame] | 15831 | // Set up HostResolver to invalidate cached entries after 1 cached resolve. |
| 15832 | session_deps_.host_resolver = |
| 15833 | std::make_unique<MockCachingHostResolver>(1 /* cache_invalidation_num */); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15834 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15835 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15836 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15837 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15838 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15839 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15840 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15841 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15842 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15843 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15844 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15845 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15846 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15847 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15848 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15849 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15850 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15851 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15852 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15853 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15854 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15855 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15856 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15857 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15858 | }; |
| 15859 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15860 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15861 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15862 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15863 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15864 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15865 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15866 | HttpRequestInfo request1; |
| 15867 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15868 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15869 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15870 | request1.traffic_annotation = |
| 15871 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15872 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15873 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15874 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15875 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15876 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15877 | |
| 15878 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15879 | ASSERT_TRUE(response); |
| 15880 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15881 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15882 | |
| 15883 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15884 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15885 | EXPECT_EQ("hello!", response_data); |
| 15886 | |
| 15887 | // Preload cache entries into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15888 | rv = session_deps_.host_resolver->LoadIntoCache( |
| 15889 | HostPortPair("mail.example.com", 443), base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15890 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15891 | |
| 15892 | HttpRequestInfo request2; |
| 15893 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15894 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15895 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15896 | request2.traffic_annotation = |
| 15897 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15898 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15899 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15900 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15901 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15902 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15903 | |
| 15904 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15905 | ASSERT_TRUE(response); |
| 15906 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15907 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15908 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15909 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15910 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15911 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15912 | } |
| 15913 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15914 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15915 | const std::string https_url = "https://www.example.org:8080/"; |
| 15916 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15917 | |
| 15918 | // SPDY GET for HTTPS URL |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15919 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15920 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15921 | |
| 15922 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15923 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15924 | }; |
| 15925 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15926 | spdy::SpdySerializedFrame resp1( |
| 15927 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15928 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15929 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15930 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15931 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15932 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15933 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 15934 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15935 | |
| 15936 | // HTTP GET for the HTTP URL |
| 15937 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15938 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15939 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15940 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15941 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15942 | }; |
| 15943 | |
| 15944 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15945 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 15946 | MockRead(ASYNC, 2, "hello"), |
| 15947 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15948 | }; |
| 15949 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15950 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15951 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15952 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15953 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15954 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15955 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15956 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15957 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15958 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15959 | |
| 15960 | // Start the first transaction to set up the SpdySession |
| 15961 | HttpRequestInfo request1; |
| 15962 | request1.method = "GET"; |
| 15963 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15964 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15965 | request1.traffic_annotation = |
| 15966 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15967 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15968 | TestCompletionCallback callback1; |
| 15969 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15970 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15971 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15972 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15973 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15974 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15975 | |
| 15976 | // Now, start the HTTP request |
| 15977 | HttpRequestInfo request2; |
| 15978 | request2.method = "GET"; |
| 15979 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15980 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15981 | request2.traffic_annotation = |
| 15982 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15983 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15984 | TestCompletionCallback callback2; |
| 15985 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15986 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15987 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15988 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15989 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15990 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15991 | } |
| 15992 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15993 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 15994 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15995 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15996 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 15997 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15998 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15999 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16000 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16001 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16002 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16003 | |
| 16004 | // No data should be read from the alternative, because HTTP/1.1 is |
| 16005 | // negotiated. |
| 16006 | StaticSocketDataProvider data; |
| 16007 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16008 | |
| 16009 | // 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] | 16010 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16011 | // mocked. This way the request relies on the alternate Job. |
| 16012 | StaticSocketDataProvider data_refused; |
| 16013 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 16014 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 16015 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16016 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16017 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16018 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16019 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16020 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16021 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16022 | http_server_properties->SetHttp2AlternativeService( |
| 16023 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16024 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16025 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16026 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16027 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16028 | request.url = GURL("https://www.example.org:443"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16029 | request.traffic_annotation = |
| 16030 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16031 | TestCompletionCallback callback; |
| 16032 | |
| 16033 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16034 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16035 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16036 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16037 | } |
| 16038 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16039 | // 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] | 16040 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16041 | // succeeds, the request should succeed, even if the latter fails because |
| 16042 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16043 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16044 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 16045 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16046 | |
| 16047 | // Negotiate HTTP/1.1 with alternative. |
| 16048 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16049 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16050 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 16051 | |
| 16052 | // No data should be read from the alternative, because HTTP/1.1 is |
| 16053 | // negotiated. |
| 16054 | StaticSocketDataProvider data; |
| 16055 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16056 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16057 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16058 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16059 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16060 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 16061 | |
| 16062 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16063 | MockWrite("GET / HTTP/1.1\r\n" |
| 16064 | "Host: www.example.org\r\n" |
| 16065 | "Connection: keep-alive\r\n\r\n"), |
| 16066 | MockWrite("GET /second HTTP/1.1\r\n" |
| 16067 | "Host: www.example.org\r\n" |
| 16068 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16069 | }; |
| 16070 | |
| 16071 | MockRead http_reads[] = { |
| 16072 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16073 | MockRead("Content-Type: text/html\r\n"), |
| 16074 | MockRead("Content-Length: 6\r\n\r\n"), |
| 16075 | MockRead("foobar"), |
| 16076 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16077 | MockRead("Content-Type: text/html\r\n"), |
| 16078 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16079 | MockRead("another"), |
| 16080 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16081 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16082 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16083 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16084 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16085 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16086 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16087 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16088 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16089 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16090 | http_server_properties->SetHttp2AlternativeService( |
| 16091 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16092 | |
| 16093 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 16094 | HttpRequestInfo request1; |
| 16095 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16096 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16097 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16098 | request1.traffic_annotation = |
| 16099 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16100 | TestCompletionCallback callback1; |
| 16101 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16102 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16103 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16104 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16105 | |
| 16106 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16107 | ASSERT_TRUE(response1); |
| 16108 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16109 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 16110 | |
| 16111 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16112 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16113 | EXPECT_EQ("foobar", response_data1); |
| 16114 | |
| 16115 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 16116 | // for alternative service. |
| 16117 | EXPECT_TRUE( |
| 16118 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 16119 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16120 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16121 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16122 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16123 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 16124 | HttpRequestInfo request2; |
| 16125 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16126 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16127 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16128 | request2.traffic_annotation = |
| 16129 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16130 | TestCompletionCallback callback2; |
| 16131 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16132 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16133 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16134 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16135 | |
| 16136 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16137 | ASSERT_TRUE(response2); |
| 16138 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16139 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 16140 | |
| 16141 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16142 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16143 | EXPECT_EQ("another", response_data2); |
| 16144 | } |
| 16145 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16146 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 16147 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 16148 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16149 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16150 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16151 | HostPortPair alternative("alternative.example.org", 443); |
| 16152 | std::string origin_url = "https://origin.example.org:443"; |
| 16153 | std::string alternative_url = "https://alternative.example.org:443"; |
| 16154 | |
| 16155 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 16156 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16157 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16158 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16159 | |
| 16160 | // HTTP/1.1 data for |request1| and |request2|. |
| 16161 | MockWrite http_writes[] = { |
| 16162 | MockWrite( |
| 16163 | "GET / HTTP/1.1\r\n" |
| 16164 | "Host: alternative.example.org\r\n" |
| 16165 | "Connection: keep-alive\r\n\r\n"), |
| 16166 | MockWrite( |
| 16167 | "GET / HTTP/1.1\r\n" |
| 16168 | "Host: alternative.example.org\r\n" |
| 16169 | "Connection: keep-alive\r\n\r\n"), |
| 16170 | }; |
| 16171 | |
| 16172 | MockRead http_reads[] = { |
| 16173 | MockRead( |
| 16174 | "HTTP/1.1 200 OK\r\n" |
| 16175 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16176 | "Content-Length: 40\r\n\r\n" |
| 16177 | "first HTTP/1.1 response from alternative"), |
| 16178 | MockRead( |
| 16179 | "HTTP/1.1 200 OK\r\n" |
| 16180 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16181 | "Content-Length: 41\r\n\r\n" |
| 16182 | "second HTTP/1.1 response from alternative"), |
| 16183 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16184 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16185 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16186 | |
| 16187 | // This test documents that an alternate Job should not pool to an already |
| 16188 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16189 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16190 | StaticSocketDataProvider data_refused; |
| 16191 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 16192 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 16193 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16194 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16195 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16196 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16197 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16198 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16199 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16200 | http_server_properties->SetHttp2AlternativeService( |
| 16201 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16202 | |
| 16203 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16204 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16205 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16206 | request1.method = "GET"; |
| 16207 | request1.url = GURL(alternative_url); |
| 16208 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16209 | request1.traffic_annotation = |
| 16210 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16211 | TestCompletionCallback callback1; |
| 16212 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16213 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16214 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16215 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16216 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16217 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16218 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16219 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16220 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 16221 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16222 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16223 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 16224 | |
| 16225 | // Request for origin.example.org, which has an alternative service. This |
| 16226 | // will start two Jobs: the alternative looks for connections to pool to, |
| 16227 | // 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] | 16228 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16229 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16230 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16231 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16232 | request2.method = "GET"; |
| 16233 | request2.url = GURL(origin_url); |
| 16234 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16235 | request2.traffic_annotation = |
| 16236 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16237 | TestCompletionCallback callback2; |
| 16238 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16239 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16240 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16241 | |
| 16242 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 16243 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16244 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16245 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16246 | request3.method = "GET"; |
| 16247 | request3.url = GURL(alternative_url); |
| 16248 | request3.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16249 | request3.traffic_annotation = |
| 16250 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16251 | TestCompletionCallback callback3; |
| 16252 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16253 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16254 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16255 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16256 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16257 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16258 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16259 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16260 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 16261 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16262 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16263 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 16264 | } |
| 16265 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16266 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16267 | const std::string https_url = "https://www.example.org:8080/"; |
| 16268 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16269 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16270 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16271 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16272 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16273 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16274 | const HostPortPair host_port_pair("www.example.org", 8080); |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 16275 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
| 16276 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 16277 | host_port_pair)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16278 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16279 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16280 | spdy::SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 16281 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 16282 | |
| 16283 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16284 | spdy::SpdyHeaderBlock req2_block; |
| 16285 | req2_block[spdy::kHttp2MethodHeader] = "GET"; |
| 16286 | req2_block[spdy::kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 16287 | req2_block[spdy::kHttp2SchemeHeader] = "http"; |
| 16288 | req2_block[spdy::kHttp2PathHeader] = "/"; |
| 16289 | spdy::SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16290 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16291 | |
| 16292 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16293 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 16294 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16295 | }; |
| 16296 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16297 | spdy::SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16298 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16299 | spdy::SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16300 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16301 | spdy::SpdySerializedFrame body1( |
| 16302 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 16303 | spdy::SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16304 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16305 | spdy::SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16306 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16307 | spdy::SpdySerializedFrame resp2( |
| 16308 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16309 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16310 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16311 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16312 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16313 | CreateMockRead(wrapped_resp1, 4), |
| 16314 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16315 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16316 | CreateMockRead(resp2, 8), |
| 16317 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16318 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 16319 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16320 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16321 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16322 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 16323 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16324 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 16325 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16326 | ProxyResolutionService::CreateFixedFromPacResult( |
| 16327 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 16328 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16329 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16330 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16331 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16332 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16333 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16334 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16335 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16336 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16337 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16338 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16339 | |
| 16340 | // Start the first transaction to set up the SpdySession |
| 16341 | HttpRequestInfo request1; |
| 16342 | request1.method = "GET"; |
| 16343 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16344 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16345 | request1.traffic_annotation = |
| 16346 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16347 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16348 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16349 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16350 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16351 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16352 | data1.RunUntilPaused(); |
| 16353 | base::RunLoop().RunUntilIdle(); |
| 16354 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16355 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16356 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16357 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16358 | LoadTimingInfo load_timing_info1; |
| 16359 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 16360 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 16361 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 16362 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16363 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16364 | HttpRequestInfo request2; |
| 16365 | request2.method = "GET"; |
| 16366 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16367 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16368 | request2.traffic_annotation = |
| 16369 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16370 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16371 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16372 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16373 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16374 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16375 | data1.RunUntilPaused(); |
| 16376 | base::RunLoop().RunUntilIdle(); |
| 16377 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16378 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16379 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16380 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16381 | |
| 16382 | LoadTimingInfo load_timing_info2; |
| 16383 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 16384 | // The established SPDY sessions is considered reused by the HTTP request. |
| 16385 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 16386 | // HTTP requests over a SPDY session should have a different connection |
| 16387 | // socket_log_id than requests over a tunnel. |
| 16388 | 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] | 16389 | } |
| 16390 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16391 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 16392 | // that we do not pool other origins that resolve to the same IP when |
| 16393 | // the certificate does not match the new origin. |
| 16394 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16395 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16396 | const std::string url1 = "http://www.example.org/"; |
| 16397 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16398 | const std::string ip_addr = "1.2.3.4"; |
| 16399 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16400 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16401 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16402 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16403 | // SPDY GET for HTTP URL (through SPDY proxy) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16404 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16405 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16406 | spdy::SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16407 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16408 | |
| 16409 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16410 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16411 | }; |
| 16412 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16413 | spdy::SpdySerializedFrame resp1( |
| 16414 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16415 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16416 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16417 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 16418 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16419 | }; |
| 16420 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16421 | SequencedSocketData data1(reads1, writes1); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 16422 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 16423 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16424 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 16425 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16426 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16427 | |
| 16428 | // SPDY GET for HTTPS URL (direct) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16429 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16430 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16431 | |
| 16432 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16433 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16434 | }; |
| 16435 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16436 | spdy::SpdySerializedFrame resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16437 | spdy_util_secure.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16438 | spdy::SpdySerializedFrame body2( |
| 16439 | spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16440 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16441 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16442 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16443 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16444 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16445 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16446 | |
| 16447 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 16448 | // all others direct. |
| 16449 | ProxyConfig proxy_config; |
| 16450 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16451 | session_deps_.proxy_resolution_service = |
| 16452 | std::make_unique<ProxyResolutionService>( |
| 16453 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 16454 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 16455 | nullptr, nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16456 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16457 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16458 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16459 | // Load a valid cert. Note, that this does not need to |
| 16460 | // be valid for proxy because the MockSSLClientSocket does |
| 16461 | // not actually verify it. But SpdySession will use this |
| 16462 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 16463 | ssl1.ssl_info.cert = |
| 16464 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 16465 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16466 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16467 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16468 | |
| 16469 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16470 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16471 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16472 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16473 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16474 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16475 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16476 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16477 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16478 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16479 | |
| 16480 | // Start the first transaction to set up the SpdySession |
| 16481 | HttpRequestInfo request1; |
| 16482 | request1.method = "GET"; |
| 16483 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16484 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16485 | request1.traffic_annotation = |
| 16486 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16487 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16488 | TestCompletionCallback callback1; |
| 16489 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16490 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16491 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16492 | data1.RunUntilPaused(); |
| 16493 | base::RunLoop().RunUntilIdle(); |
| 16494 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16495 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16496 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16497 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16498 | |
| 16499 | // Now, start the HTTP request |
| 16500 | HttpRequestInfo request2; |
| 16501 | request2.method = "GET"; |
| 16502 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16503 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16504 | request2.traffic_annotation = |
| 16505 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16506 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16507 | TestCompletionCallback callback2; |
| 16508 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16509 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16510 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16511 | |
| 16512 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16513 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16514 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16515 | } |
| 16516 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16517 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 16518 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 16519 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 16520 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16521 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16522 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16523 | |
| 16524 | MockRead reads1[] = { |
| 16525 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 16526 | }; |
| 16527 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16528 | SequencedSocketData data1(reads1, base::span<MockWrite>()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16529 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16530 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16531 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16532 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16533 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16534 | }; |
| 16535 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16536 | spdy::SpdySerializedFrame resp2( |
| 16537 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16538 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16539 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16540 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 16541 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16542 | }; |
| 16543 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16544 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16545 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16546 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16547 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16548 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16549 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16550 | |
| 16551 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16552 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16553 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16554 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16555 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16556 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16557 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16558 | |
| 16559 | // Start the first transaction to set up the SpdySession and verify that |
| 16560 | // connection was closed. |
| 16561 | HttpRequestInfo request1; |
| 16562 | request1.method = "GET"; |
| 16563 | request1.url = GURL(https_url); |
| 16564 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16565 | request1.traffic_annotation = |
| 16566 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16567 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16568 | TestCompletionCallback callback1; |
| 16569 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16570 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16571 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16572 | |
| 16573 | // Now, start the second request and make sure it succeeds. |
| 16574 | HttpRequestInfo request2; |
| 16575 | request2.method = "GET"; |
| 16576 | request2.url = GURL(https_url); |
| 16577 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16578 | request2.traffic_annotation = |
| 16579 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16580 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16581 | TestCompletionCallback callback2; |
| 16582 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16583 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16584 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16585 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16586 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16587 | } |
| 16588 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16589 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16590 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16591 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16592 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16593 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16594 | |
| 16595 | // Use two different hosts with different IPs so they don't get pooled. |
| 16596 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 16597 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16598 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16599 | |
| 16600 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16601 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16602 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16603 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16604 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16605 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16606 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16607 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16608 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16609 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16610 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16611 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16612 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16613 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16614 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16615 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16616 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16617 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16618 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16619 | }; |
| 16620 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16621 | // Use a separate test instance for the separate SpdySession that will be |
| 16622 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16623 | SpdyTestUtil spdy_util_2; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16624 | SequencedSocketData spdy1_data(spdy1_reads, spdy1_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 16625 | session_deps_.socket_factory->AddSocketDataProvider(&spdy1_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16626 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16627 | spdy::SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16628 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16629 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16630 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16631 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16632 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16633 | spdy_util_2.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16634 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16635 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16636 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16637 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16638 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16639 | }; |
| 16640 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16641 | SequencedSocketData spdy2_data(spdy2_reads, spdy2_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 16642 | session_deps_.socket_factory->AddSocketDataProvider(&spdy2_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16643 | |
| 16644 | MockWrite http_write[] = { |
| 16645 | MockWrite("GET / HTTP/1.1\r\n" |
| 16646 | "Host: www.a.com\r\n" |
| 16647 | "Connection: keep-alive\r\n\r\n"), |
| 16648 | }; |
| 16649 | |
| 16650 | MockRead http_read[] = { |
| 16651 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16652 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 16653 | MockRead("Content-Length: 6\r\n\r\n"), |
| 16654 | MockRead("hello!"), |
| 16655 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16656 | StaticSocketDataProvider http_data(http_read, http_write); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16657 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16658 | |
| 16659 | HostPortPair host_port_pair_a("www.a.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16660 | SpdySessionKey spdy_session_key_a( |
| 16661 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16662 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16663 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16664 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16665 | |
| 16666 | TestCompletionCallback callback; |
| 16667 | HttpRequestInfo request1; |
| 16668 | request1.method = "GET"; |
| 16669 | request1.url = GURL("https://www.a.com/"); |
| 16670 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16671 | request1.traffic_annotation = |
| 16672 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16673 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16674 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16675 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16676 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16677 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16678 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16679 | |
| 16680 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16681 | ASSERT_TRUE(response); |
| 16682 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16683 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16684 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16685 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16686 | |
| 16687 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16688 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16689 | EXPECT_EQ("hello!", response_data); |
| 16690 | trans.reset(); |
| 16691 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16692 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16693 | |
| 16694 | HostPortPair host_port_pair_b("www.b.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16695 | SpdySessionKey spdy_session_key_b( |
| 16696 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16697 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16698 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16699 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16700 | HttpRequestInfo request2; |
| 16701 | request2.method = "GET"; |
| 16702 | request2.url = GURL("https://www.b.com/"); |
| 16703 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16704 | request2.traffic_annotation = |
| 16705 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16706 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16707 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16708 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16709 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16710 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16711 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16712 | |
| 16713 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16714 | ASSERT_TRUE(response); |
| 16715 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16716 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16717 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16718 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16719 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16720 | EXPECT_EQ("hello!", response_data); |
| 16721 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16722 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16723 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16724 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16725 | |
| 16726 | HostPortPair host_port_pair_a1("www.a.com", 80); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16727 | SpdySessionKey spdy_session_key_a1( |
| 16728 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16729 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16730 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16731 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16732 | HttpRequestInfo request3; |
| 16733 | request3.method = "GET"; |
| 16734 | request3.url = GURL("http://www.a.com/"); |
| 16735 | request3.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16736 | request3.traffic_annotation = |
| 16737 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16738 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16739 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16740 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16741 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16742 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16743 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16744 | |
| 16745 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16746 | ASSERT_TRUE(response); |
| 16747 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16748 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 16749 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16750 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16751 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16752 | EXPECT_EQ("hello!", response_data); |
| 16753 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16754 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16755 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16756 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16757 | } |
| 16758 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16759 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16760 | HttpRequestInfo request; |
| 16761 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16762 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16763 | request.traffic_annotation = |
| 16764 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16765 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16766 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16767 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16768 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16769 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16770 | StaticSocketDataProvider data; |
| 16771 | data.set_connect_data(mock_connect); |
| 16772 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16773 | |
| 16774 | TestCompletionCallback callback; |
| 16775 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16776 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16777 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16778 | |
| 16779 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16780 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16781 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16782 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16783 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16784 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16785 | |
| 16786 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16787 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16788 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16789 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16790 | |
| 16791 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16792 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16793 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16794 | } |
| 16795 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16796 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16797 | HttpRequestInfo request; |
| 16798 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16799 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16800 | request.traffic_annotation = |
| 16801 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16802 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16803 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16804 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16805 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16806 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16807 | StaticSocketDataProvider data; |
| 16808 | data.set_connect_data(mock_connect); |
| 16809 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16810 | |
| 16811 | TestCompletionCallback callback; |
| 16812 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16813 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16814 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16815 | |
| 16816 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16817 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16818 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16819 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16820 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16821 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16822 | |
| 16823 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16824 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16825 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16826 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16827 | |
| 16828 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16829 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16830 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16831 | } |
| 16832 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16833 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16834 | HttpRequestInfo request; |
| 16835 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16836 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16837 | request.traffic_annotation = |
| 16838 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16839 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16840 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16841 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16842 | |
| 16843 | MockWrite data_writes[] = { |
| 16844 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16845 | }; |
| 16846 | MockRead data_reads[] = { |
| 16847 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16848 | }; |
| 16849 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16850 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16851 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16852 | |
| 16853 | TestCompletionCallback callback; |
| 16854 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16855 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16856 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16857 | |
| 16858 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16859 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16860 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16861 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16862 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16863 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16864 | } |
| 16865 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16866 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16867 | HttpRequestInfo request; |
| 16868 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16869 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16870 | request.traffic_annotation = |
| 16871 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16872 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16873 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16874 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16875 | |
| 16876 | MockWrite data_writes[] = { |
| 16877 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 16878 | }; |
| 16879 | MockRead data_reads[] = { |
| 16880 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16881 | }; |
| 16882 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16883 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16884 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16885 | |
| 16886 | TestCompletionCallback callback; |
| 16887 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16888 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16889 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16890 | |
| 16891 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16892 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16893 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16894 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16895 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16896 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16897 | } |
| 16898 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16899 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16900 | HttpRequestInfo request; |
| 16901 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16902 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16903 | request.traffic_annotation = |
| 16904 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16905 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16906 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16907 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16908 | |
| 16909 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16910 | MockWrite( |
| 16911 | "GET / HTTP/1.1\r\n" |
| 16912 | "Host: www.example.org\r\n" |
| 16913 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16914 | }; |
| 16915 | MockRead data_reads[] = { |
| 16916 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16917 | }; |
| 16918 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16919 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16920 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16921 | |
| 16922 | TestCompletionCallback callback; |
| 16923 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16924 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16925 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16926 | |
| 16927 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16928 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16929 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16930 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16931 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16932 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16933 | } |
| 16934 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16935 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16936 | HttpRequestInfo request; |
| 16937 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16938 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16939 | request.traffic_annotation = |
| 16940 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16941 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16942 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16943 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16944 | |
| 16945 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16946 | MockWrite( |
| 16947 | "GET / HTTP/1.1\r\n" |
| 16948 | "Host: www.example.org\r\n" |
| 16949 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16950 | }; |
| 16951 | MockRead data_reads[] = { |
| 16952 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 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, GetFullRequestHeadersIncludesExtraHeader) { |
[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/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16975 | request.extra_headers.SetHeader("X-Foo", "bar"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16976 | request.traffic_annotation = |
| 16977 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16978 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16979 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16980 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16981 | |
| 16982 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16983 | MockWrite( |
| 16984 | "GET / HTTP/1.1\r\n" |
| 16985 | "Host: www.example.org\r\n" |
| 16986 | "Connection: keep-alive\r\n" |
| 16987 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16988 | }; |
| 16989 | MockRead data_reads[] = { |
| 16990 | MockRead("HTTP/1.1 200 OK\r\n" |
| 16991 | "Content-Length: 5\r\n\r\n" |
| 16992 | "hello"), |
| 16993 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 16994 | }; |
| 16995 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16996 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16997 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16998 | |
| 16999 | TestCompletionCallback callback; |
| 17000 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17001 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17002 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17003 | |
| 17004 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17005 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17006 | |
| 17007 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17008 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17009 | std::string foo; |
| 17010 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 17011 | EXPECT_EQ("bar", foo); |
| 17012 | } |
| 17013 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17014 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 17015 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17016 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17017 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17018 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17019 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17020 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17021 | |
| 17022 | // Set up SSL request. |
| 17023 | |
| 17024 | HttpRequestInfo ssl_request; |
| 17025 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17026 | ssl_request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17027 | ssl_request.traffic_annotation = |
| 17028 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17029 | |
| 17030 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17031 | MockWrite( |
| 17032 | "GET / HTTP/1.1\r\n" |
| 17033 | "Host: www.example.org\r\n" |
| 17034 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17035 | }; |
| 17036 | MockRead ssl_reads[] = { |
| 17037 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17038 | MockRead("Content-Length: 11\r\n\r\n"), |
| 17039 | MockRead("hello world"), |
| 17040 | MockRead(SYNCHRONOUS, OK), |
| 17041 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17042 | StaticSocketDataProvider ssl_data(ssl_reads, ssl_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17043 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 17044 | |
| 17045 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17046 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17047 | |
| 17048 | // Set up HTTP request. |
| 17049 | |
| 17050 | HttpRequestInfo http_request; |
| 17051 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17052 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17053 | http_request.traffic_annotation = |
| 17054 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17055 | |
| 17056 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17057 | MockWrite( |
| 17058 | "GET / HTTP/1.1\r\n" |
| 17059 | "Host: www.example.org\r\n" |
| 17060 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17061 | }; |
| 17062 | MockRead http_reads[] = { |
| 17063 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17064 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17065 | MockRead("falafel"), |
| 17066 | MockRead(SYNCHRONOUS, OK), |
| 17067 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17068 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17069 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17070 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17071 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17072 | |
| 17073 | // Start the SSL request. |
| 17074 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17075 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17076 | ASSERT_EQ(ERR_IO_PENDING, |
| 17077 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 17078 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17079 | |
| 17080 | // Start the HTTP request. Pool should stall. |
| 17081 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17082 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17083 | ASSERT_EQ(ERR_IO_PENDING, |
| 17084 | http_trans.Start(&http_request, http_callback.callback(), |
| 17085 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17086 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17087 | |
| 17088 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17089 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17090 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17091 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17092 | EXPECT_EQ("hello world", response_data); |
| 17093 | |
| 17094 | // The SSL socket should automatically be closed, so the HTTP request can |
| 17095 | // start. |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 17096 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17097 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17098 | |
| 17099 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17100 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17101 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17102 | EXPECT_EQ("falafel", response_data); |
| 17103 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17104 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17105 | } |
| 17106 | |
| 17107 | // Tests that when a SSL connection is established but there's no corresponding |
| 17108 | // request that needs it, the new socket is closed if the transport socket pool |
| 17109 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17110 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17111 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17112 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17113 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17114 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17115 | |
| 17116 | // Set up an ssl request. |
| 17117 | |
| 17118 | HttpRequestInfo ssl_request; |
| 17119 | ssl_request.method = "GET"; |
| 17120 | ssl_request.url = GURL("https://www.foopy.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17121 | ssl_request.traffic_annotation = |
| 17122 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17123 | |
| 17124 | // No data will be sent on the SSL socket. |
| 17125 | StaticSocketDataProvider ssl_data; |
| 17126 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 17127 | |
| 17128 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17129 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17130 | |
| 17131 | // Set up HTTP request. |
| 17132 | |
| 17133 | HttpRequestInfo http_request; |
| 17134 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17135 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17136 | http_request.traffic_annotation = |
| 17137 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17138 | |
| 17139 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17140 | MockWrite( |
| 17141 | "GET / HTTP/1.1\r\n" |
| 17142 | "Host: www.example.org\r\n" |
| 17143 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17144 | }; |
| 17145 | MockRead http_reads[] = { |
| 17146 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17147 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17148 | MockRead("falafel"), |
| 17149 | MockRead(SYNCHRONOUS, OK), |
| 17150 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17151 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17152 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17153 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17154 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17155 | |
| 17156 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 17157 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 17158 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 17159 | http_stream_factory->PreconnectStreams(1, ssl_request); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 17160 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17161 | |
| 17162 | // Start the HTTP request. Pool should stall. |
| 17163 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17164 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17165 | ASSERT_EQ(ERR_IO_PENDING, |
| 17166 | http_trans.Start(&http_request, http_callback.callback(), |
| 17167 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17168 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17169 | |
| 17170 | // The SSL connection will automatically be closed once the connection is |
| 17171 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17172 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17173 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17174 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17175 | EXPECT_EQ("falafel", response_data); |
| 17176 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17177 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17178 | } |
| 17179 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17180 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17181 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17182 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17183 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17184 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17185 | |
| 17186 | HttpRequestInfo request; |
| 17187 | request.method = "POST"; |
| 17188 | request.url = GURL("http://www.foo.com/"); |
| 17189 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17190 | request.traffic_annotation = |
| 17191 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17192 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17193 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17194 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17195 | // Send headers successfully, but get an error while sending the body. |
| 17196 | MockWrite data_writes[] = { |
| 17197 | MockWrite("POST / HTTP/1.1\r\n" |
| 17198 | "Host: www.foo.com\r\n" |
| 17199 | "Connection: keep-alive\r\n" |
| 17200 | "Content-Length: 3\r\n\r\n"), |
| 17201 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17202 | }; |
| 17203 | |
| 17204 | MockRead data_reads[] = { |
| 17205 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17206 | MockRead("hello world"), |
| 17207 | MockRead(SYNCHRONOUS, OK), |
| 17208 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17209 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17210 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17211 | |
| 17212 | TestCompletionCallback callback; |
| 17213 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17214 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17215 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17216 | |
| 17217 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17218 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17219 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17220 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17221 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17222 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17223 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17224 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17225 | |
| 17226 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17227 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17228 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17229 | EXPECT_EQ("hello world", response_data); |
| 17230 | } |
| 17231 | |
| 17232 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 17233 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17234 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17235 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17236 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17237 | MockWrite data_writes[] = { |
| 17238 | MockWrite("GET / HTTP/1.1\r\n" |
| 17239 | "Host: www.foo.com\r\n" |
| 17240 | "Connection: keep-alive\r\n\r\n"), |
| 17241 | MockWrite("POST / HTTP/1.1\r\n" |
| 17242 | "Host: www.foo.com\r\n" |
| 17243 | "Connection: keep-alive\r\n" |
| 17244 | "Content-Length: 3\r\n\r\n"), |
| 17245 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17246 | }; |
| 17247 | |
| 17248 | MockRead data_reads[] = { |
| 17249 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 17250 | "Content-Length: 14\r\n\r\n"), |
| 17251 | MockRead("first response"), |
| 17252 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 17253 | "Content-Length: 15\r\n\r\n"), |
| 17254 | MockRead("second response"), |
| 17255 | MockRead(SYNCHRONOUS, OK), |
| 17256 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17257 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17258 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17259 | |
| 17260 | TestCompletionCallback callback; |
| 17261 | HttpRequestInfo request1; |
| 17262 | request1.method = "GET"; |
| 17263 | request1.url = GURL("http://www.foo.com/"); |
| 17264 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17265 | request1.traffic_annotation = |
| 17266 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17267 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17268 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17269 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17270 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17271 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17272 | |
| 17273 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17274 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17275 | |
| 17276 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17277 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17278 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17279 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17280 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 17281 | |
| 17282 | std::string response_data1; |
| 17283 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17284 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17285 | EXPECT_EQ("first response", response_data1); |
| 17286 | // Delete the transaction to release the socket back into the socket pool. |
| 17287 | trans1.reset(); |
| 17288 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17289 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17290 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17291 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17292 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17293 | |
| 17294 | HttpRequestInfo request2; |
| 17295 | request2.method = "POST"; |
| 17296 | request2.url = GURL("http://www.foo.com/"); |
| 17297 | request2.upload_data_stream = &upload_data_stream; |
| 17298 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17299 | request2.traffic_annotation = |
| 17300 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17301 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17302 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17303 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17304 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17305 | |
| 17306 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17307 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17308 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17309 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17310 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17311 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17312 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17313 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 17314 | |
| 17315 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17316 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17317 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17318 | EXPECT_EQ("second response", response_data2); |
| 17319 | } |
| 17320 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17321 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17322 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17323 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17324 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17325 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17326 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17327 | |
| 17328 | HttpRequestInfo request; |
| 17329 | request.method = "POST"; |
| 17330 | request.url = GURL("http://www.foo.com/"); |
| 17331 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17332 | request.traffic_annotation = |
| 17333 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17334 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17335 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17336 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17337 | // Send headers successfully, but get an error while sending the body. |
| 17338 | MockWrite data_writes[] = { |
| 17339 | MockWrite("POST / HTTP/1.1\r\n" |
| 17340 | "Host: www.foo.com\r\n" |
| 17341 | "Connection: keep-alive\r\n" |
| 17342 | "Content-Length: 3\r\n\r\n" |
| 17343 | "fo"), |
| 17344 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17345 | }; |
| 17346 | |
| 17347 | MockRead data_reads[] = { |
| 17348 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17349 | MockRead("hello world"), |
| 17350 | MockRead(SYNCHRONOUS, OK), |
| 17351 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17352 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17353 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17354 | |
| 17355 | TestCompletionCallback callback; |
| 17356 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17357 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17358 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17359 | |
| 17360 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17361 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17362 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17363 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17364 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17365 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17366 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17367 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17368 | |
| 17369 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17370 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17371 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17372 | EXPECT_EQ("hello world", response_data); |
| 17373 | } |
| 17374 | |
| 17375 | // This tests the more common case than the previous test, where headers and |
| 17376 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17377 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17378 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17379 | |
| 17380 | HttpRequestInfo request; |
| 17381 | request.method = "POST"; |
| 17382 | request.url = GURL("http://www.foo.com/"); |
| 17383 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17384 | request.traffic_annotation = |
| 17385 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17386 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17387 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17388 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17389 | // Send headers successfully, but get an error while sending the body. |
| 17390 | MockWrite data_writes[] = { |
| 17391 | MockWrite("POST / HTTP/1.1\r\n" |
| 17392 | "Host: www.foo.com\r\n" |
| 17393 | "Connection: keep-alive\r\n" |
| 17394 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17395 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17396 | }; |
| 17397 | |
| 17398 | MockRead data_reads[] = { |
| 17399 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17400 | MockRead("hello world"), |
| 17401 | MockRead(SYNCHRONOUS, OK), |
| 17402 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17403 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17404 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17405 | |
| 17406 | TestCompletionCallback callback; |
| 17407 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17408 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17409 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17410 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 17411 | // they can't be merged with the body in a single send. Not currently |
| 17412 | // necessary since a chunked body is never merged with headers, but this makes |
| 17413 | // the test more future proof. |
| 17414 | base::RunLoop().RunUntilIdle(); |
| 17415 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17416 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17417 | |
| 17418 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17419 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17420 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17421 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17422 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17423 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17424 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17425 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17426 | |
| 17427 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17428 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17429 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17430 | EXPECT_EQ("hello world", response_data); |
| 17431 | } |
| 17432 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17433 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17434 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17435 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17436 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17437 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17438 | |
| 17439 | HttpRequestInfo request; |
| 17440 | request.method = "POST"; |
| 17441 | request.url = GURL("http://www.foo.com/"); |
| 17442 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17443 | request.traffic_annotation = |
| 17444 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17445 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17446 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17447 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17448 | |
| 17449 | MockWrite data_writes[] = { |
| 17450 | MockWrite("POST / HTTP/1.1\r\n" |
| 17451 | "Host: www.foo.com\r\n" |
| 17452 | "Connection: keep-alive\r\n" |
| 17453 | "Content-Length: 3\r\n\r\n"), |
| 17454 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17455 | }; |
| 17456 | |
| 17457 | MockRead data_reads[] = { |
| 17458 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17459 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17460 | MockRead("hello world"), |
| 17461 | MockRead(SYNCHRONOUS, OK), |
| 17462 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17463 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17464 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17465 | |
| 17466 | TestCompletionCallback callback; |
| 17467 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17468 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17469 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17470 | |
| 17471 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17472 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17473 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17474 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17475 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17476 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17477 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17478 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17479 | |
| 17480 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17481 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17482 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17483 | EXPECT_EQ("hello world", response_data); |
| 17484 | } |
| 17485 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17486 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17487 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17488 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17489 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17490 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17491 | |
| 17492 | HttpRequestInfo request; |
| 17493 | request.method = "POST"; |
| 17494 | request.url = GURL("http://www.foo.com/"); |
| 17495 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17496 | request.traffic_annotation = |
| 17497 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17498 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17499 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17500 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17501 | // Send headers successfully, but get an error while sending the body. |
| 17502 | MockWrite data_writes[] = { |
| 17503 | MockWrite("POST / HTTP/1.1\r\n" |
| 17504 | "Host: www.foo.com\r\n" |
| 17505 | "Connection: keep-alive\r\n" |
| 17506 | "Content-Length: 3\r\n\r\n"), |
| 17507 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17508 | }; |
| 17509 | |
| 17510 | MockRead data_reads[] = { |
| 17511 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 17512 | MockRead("hello world"), |
| 17513 | MockRead(SYNCHRONOUS, OK), |
| 17514 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17515 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17516 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17517 | |
| 17518 | TestCompletionCallback callback; |
| 17519 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17520 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17521 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[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, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17525 | } |
| 17526 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17527 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17528 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17529 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17530 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17531 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17532 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17533 | |
| 17534 | HttpRequestInfo request; |
| 17535 | request.method = "POST"; |
| 17536 | request.url = GURL("http://www.foo.com/"); |
| 17537 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17538 | request.traffic_annotation = |
| 17539 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17540 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17541 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17542 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17543 | // Send headers successfully, but get an error while sending the body. |
| 17544 | MockWrite data_writes[] = { |
| 17545 | MockWrite("POST / HTTP/1.1\r\n" |
| 17546 | "Host: www.foo.com\r\n" |
| 17547 | "Connection: keep-alive\r\n" |
| 17548 | "Content-Length: 3\r\n\r\n"), |
| 17549 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17550 | }; |
| 17551 | |
| 17552 | MockRead data_reads[] = { |
| 17553 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17554 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 17555 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 17556 | MockRead("Content-Length: 0\r\n\r\n"), |
| 17557 | MockRead(SYNCHRONOUS, OK), |
| 17558 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17559 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17560 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17561 | |
| 17562 | TestCompletionCallback callback; |
| 17563 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17564 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17565 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17566 | |
| 17567 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17568 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17569 | } |
| 17570 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17571 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17572 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17573 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17574 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17575 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17576 | |
| 17577 | HttpRequestInfo request; |
| 17578 | request.method = "POST"; |
| 17579 | request.url = GURL("http://www.foo.com/"); |
| 17580 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17581 | request.traffic_annotation = |
| 17582 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17583 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17584 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17585 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17586 | // Send headers successfully, but get an error while sending the body. |
| 17587 | MockWrite data_writes[] = { |
| 17588 | MockWrite("POST / HTTP/1.1\r\n" |
| 17589 | "Host: www.foo.com\r\n" |
| 17590 | "Connection: keep-alive\r\n" |
| 17591 | "Content-Length: 3\r\n\r\n"), |
| 17592 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17593 | }; |
| 17594 | |
| 17595 | MockRead data_reads[] = { |
| 17596 | MockRead("HTTP 0.9 rocks!"), |
| 17597 | MockRead(SYNCHRONOUS, OK), |
| 17598 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17599 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17600 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17601 | |
| 17602 | TestCompletionCallback callback; |
| 17603 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17604 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17605 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17606 | |
| 17607 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17608 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17609 | } |
| 17610 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17611 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17612 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17613 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17614 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17615 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17616 | |
| 17617 | HttpRequestInfo request; |
| 17618 | request.method = "POST"; |
| 17619 | request.url = GURL("http://www.foo.com/"); |
| 17620 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17621 | request.traffic_annotation = |
| 17622 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17623 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17624 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17625 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17626 | // Send headers successfully, but get an error while sending the body. |
| 17627 | MockWrite data_writes[] = { |
| 17628 | MockWrite("POST / HTTP/1.1\r\n" |
| 17629 | "Host: www.foo.com\r\n" |
| 17630 | "Connection: keep-alive\r\n" |
| 17631 | "Content-Length: 3\r\n\r\n"), |
| 17632 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17633 | }; |
| 17634 | |
| 17635 | MockRead data_reads[] = { |
| 17636 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 17637 | MockRead(SYNCHRONOUS, OK), |
| 17638 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17639 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17640 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17641 | |
| 17642 | TestCompletionCallback callback; |
| 17643 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17644 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17645 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17646 | |
| 17647 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17648 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17649 | } |
| 17650 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17651 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17652 | |
| 17653 | namespace { |
| 17654 | |
| 17655 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
| 17656 | headers->SetHeader("Connection", "Upgrade"); |
| 17657 | headers->SetHeader("Upgrade", "websocket"); |
| 17658 | headers->SetHeader("Origin", "http://www.example.org"); |
| 17659 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17660 | } |
| 17661 | |
| 17662 | } // namespace |
| 17663 | |
| 17664 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17665 | for (bool secure : {true, false}) { |
| 17666 | MockWrite data_writes[] = { |
| 17667 | MockWrite("GET / HTTP/1.1\r\n" |
| 17668 | "Host: www.example.org\r\n" |
| 17669 | "Connection: Upgrade\r\n" |
| 17670 | "Upgrade: websocket\r\n" |
| 17671 | "Origin: http://www.example.org\r\n" |
| 17672 | "Sec-WebSocket-Version: 13\r\n" |
| 17673 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17674 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17675 | "client_max_window_bits\r\n\r\n")}; |
| 17676 | |
| 17677 | MockRead data_reads[] = { |
| 17678 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17679 | "Upgrade: websocket\r\n" |
| 17680 | "Connection: Upgrade\r\n" |
| 17681 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
| 17682 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17683 | StaticSocketDataProvider data(data_reads, data_writes); |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17684 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17685 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17686 | if (secure) |
| 17687 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17688 | |
| 17689 | HttpRequestInfo request; |
| 17690 | request.method = "GET"; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17691 | request.url = |
| 17692 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 17693 | AddWebSocketHeaders(&request.extra_headers); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17694 | request.traffic_annotation = |
| 17695 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17696 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17697 | TestWebSocketHandshakeStreamCreateHelper |
| 17698 | websocket_handshake_stream_create_helper; |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17699 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17700 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17701 | HttpNetworkTransaction trans(LOW, session.get()); |
| 17702 | trans.SetWebSocketHandshakeStreamCreateHelper( |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17703 | &websocket_handshake_stream_create_helper); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17704 | |
| 17705 | TestCompletionCallback callback; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17706 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17707 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17708 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17709 | const HttpStreamRequest* stream_request = trans.stream_request_.get(); |
| 17710 | ASSERT_TRUE(stream_request); |
| 17711 | EXPECT_EQ(&websocket_handshake_stream_create_helper, |
| 17712 | stream_request->websocket_handshake_stream_create_helper()); |
| 17713 | |
| 17714 | rv = callback.WaitForResult(); |
| 17715 | EXPECT_THAT(rv, IsOk()); |
| 17716 | |
| 17717 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 17718 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17719 | } |
| 17720 | } |
| 17721 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17722 | // Verify that proxy headers are not sent to the destination server when |
| 17723 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17724 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17725 | HttpRequestInfo request; |
| 17726 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17727 | request.url = GURL("wss://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17728 | request.traffic_annotation = |
| 17729 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17730 | AddWebSocketHeaders(&request.extra_headers); |
| 17731 | |
| 17732 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17733 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17734 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17735 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17736 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17737 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17738 | |
| 17739 | // Since a proxy is configured, try to establish a tunnel. |
| 17740 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17741 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17742 | "Host: www.example.org:443\r\n" |
| 17743 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17744 | |
| 17745 | // After calling trans->RestartWithAuth(), this is the request we should |
| 17746 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17747 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17748 | "Host: www.example.org:443\r\n" |
| 17749 | "Proxy-Connection: keep-alive\r\n" |
| 17750 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17751 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17752 | MockWrite("GET / HTTP/1.1\r\n" |
| 17753 | "Host: www.example.org\r\n" |
| 17754 | "Connection: Upgrade\r\n" |
| 17755 | "Upgrade: websocket\r\n" |
| 17756 | "Origin: http://www.example.org\r\n" |
| 17757 | "Sec-WebSocket-Version: 13\r\n" |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17758 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17759 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17760 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17761 | |
| 17762 | // The proxy responds to the connect with a 407, using a persistent |
| 17763 | // connection. |
| 17764 | MockRead data_reads[] = { |
| 17765 | // No credentials. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17766 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 17767 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 17768 | "Content-Length: 0\r\n" |
| 17769 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17770 | |
| 17771 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17772 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17773 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17774 | "Upgrade: websocket\r\n" |
| 17775 | "Connection: Upgrade\r\n" |
| 17776 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17777 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17778 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17779 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17780 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17781 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17782 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17783 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17784 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17785 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17786 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17787 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17788 | &websocket_stream_create_helper); |
| 17789 | |
| 17790 | { |
| 17791 | TestCompletionCallback callback; |
| 17792 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17793 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17794 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17795 | |
| 17796 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17797 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17798 | } |
| 17799 | |
| 17800 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17801 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17802 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17803 | EXPECT_EQ(407, response->headers->response_code()); |
| 17804 | |
| 17805 | { |
| 17806 | TestCompletionCallback callback; |
| 17807 | |
| 17808 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 17809 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17810 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17811 | |
| 17812 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17813 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17814 | } |
| 17815 | |
| 17816 | response = trans->GetResponseInfo(); |
| 17817 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17818 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17819 | |
| 17820 | EXPECT_EQ(101, response->headers->response_code()); |
| 17821 | |
| 17822 | trans.reset(); |
| 17823 | session->CloseAllConnections(); |
| 17824 | } |
| 17825 | |
| 17826 | // Verify that proxy headers are not sent to the destination server when |
| 17827 | // establishing a tunnel for an insecure WebSocket connection. |
| 17828 | // This requires the authentication info to be injected into the auth cache |
| 17829 | // due to crbug.com/395064 |
| 17830 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17831 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17832 | HttpRequestInfo request; |
| 17833 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17834 | request.url = GURL("ws://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17835 | request.traffic_annotation = |
| 17836 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17837 | AddWebSocketHeaders(&request.extra_headers); |
| 17838 | |
| 17839 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17840 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17841 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17842 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17843 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17844 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17845 | |
| 17846 | MockWrite data_writes[] = { |
| 17847 | // Try to establish a tunnel for the WebSocket connection, with |
| 17848 | // credentials. Because WebSockets have a separate set of socket pools, |
| 17849 | // they cannot and will not use the same TCP/IP connection as the |
| 17850 | // preflight HTTP request. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17851 | MockWrite("CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 17852 | "Host: www.example.org:80\r\n" |
| 17853 | "Proxy-Connection: keep-alive\r\n" |
| 17854 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17855 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17856 | MockWrite("GET / HTTP/1.1\r\n" |
| 17857 | "Host: www.example.org\r\n" |
| 17858 | "Connection: Upgrade\r\n" |
| 17859 | "Upgrade: websocket\r\n" |
| 17860 | "Origin: http://www.example.org\r\n" |
| 17861 | "Sec-WebSocket-Version: 13\r\n" |
| 17862 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17863 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17864 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17865 | |
| 17866 | MockRead data_reads[] = { |
| 17867 | // HTTP CONNECT with credentials. |
| 17868 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17869 | |
| 17870 | // WebSocket connection established inside tunnel. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17871 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17872 | "Upgrade: websocket\r\n" |
| 17873 | "Connection: Upgrade\r\n" |
| 17874 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17875 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17876 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17877 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17878 | |
| 17879 | session->http_auth_cache()->Add( |
| 17880 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 17881 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 17882 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17883 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17884 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17885 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17886 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17887 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17888 | &websocket_stream_create_helper); |
| 17889 | |
| 17890 | TestCompletionCallback callback; |
| 17891 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17892 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17893 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17894 | |
| 17895 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17896 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17897 | |
| 17898 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17899 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17900 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17901 | |
| 17902 | EXPECT_EQ(101, response->headers->response_code()); |
| 17903 | |
| 17904 | trans.reset(); |
| 17905 | session->CloseAllConnections(); |
| 17906 | } |
| 17907 | |
Matt Menke | 1d6093e3 | 2019-03-22 17:33:43 | [diff] [blame] | 17908 | // WebSockets over QUIC is not supported, including over QUIC proxies. |
| 17909 | TEST_F(HttpNetworkTransactionTest, WebSocketNotSentOverQuicProxy) { |
| 17910 | for (bool secure : {true, false}) { |
| 17911 | SCOPED_TRACE(secure); |
| 17912 | session_deps_.proxy_resolution_service = |
| 17913 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17914 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 17915 | session_deps_.enable_quic = true; |
| 17916 | |
| 17917 | HttpRequestInfo request; |
| 17918 | request.url = |
| 17919 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 17920 | AddWebSocketHeaders(&request.extra_headers); |
| 17921 | request.traffic_annotation = |
| 17922 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 17923 | |
| 17924 | TestWebSocketHandshakeStreamCreateHelper |
| 17925 | websocket_handshake_stream_create_helper; |
| 17926 | |
| 17927 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17928 | HttpNetworkTransaction trans(LOW, session.get()); |
| 17929 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 17930 | &websocket_handshake_stream_create_helper); |
| 17931 | |
| 17932 | TestCompletionCallback callback; |
| 17933 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17934 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17935 | |
| 17936 | rv = callback.WaitForResult(); |
| 17937 | EXPECT_THAT(rv, IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 17938 | } |
| 17939 | } |
| 17940 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17941 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17942 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17943 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17944 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17945 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17946 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17947 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17948 | |
| 17949 | HttpRequestInfo request; |
| 17950 | request.method = "POST"; |
| 17951 | request.url = GURL("http://www.foo.com/"); |
| 17952 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17953 | request.traffic_annotation = |
| 17954 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17955 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17956 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17957 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17958 | MockWrite data_writes[] = { |
| 17959 | MockWrite("POST / HTTP/1.1\r\n" |
| 17960 | "Host: www.foo.com\r\n" |
| 17961 | "Connection: keep-alive\r\n" |
| 17962 | "Content-Length: 3\r\n\r\n"), |
| 17963 | MockWrite("foo"), |
| 17964 | }; |
| 17965 | |
| 17966 | MockRead data_reads[] = { |
| 17967 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17968 | MockRead(SYNCHRONOUS, OK), |
| 17969 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17970 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17971 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17972 | |
| 17973 | TestCompletionCallback callback; |
| 17974 | |
| 17975 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17976 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17977 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17978 | |
| 17979 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17980 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17981 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17982 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 17983 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17984 | } |
| 17985 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17986 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17987 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17988 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17989 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17990 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17991 | |
| 17992 | HttpRequestInfo request; |
| 17993 | request.method = "POST"; |
| 17994 | request.url = GURL("http://www.foo.com/"); |
| 17995 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17996 | request.traffic_annotation = |
| 17997 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17998 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17999 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18000 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18001 | MockWrite data_writes[] = { |
| 18002 | MockWrite("POST / HTTP/1.1\r\n" |
| 18003 | "Host: www.foo.com\r\n" |
| 18004 | "Connection: keep-alive\r\n" |
| 18005 | "Content-Length: 3\r\n\r\n"), |
| 18006 | MockWrite("foo"), |
| 18007 | }; |
| 18008 | |
| 18009 | MockRead data_reads[] = { |
| 18010 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 18011 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18012 | MockRead(SYNCHRONOUS, OK), |
| 18013 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18014 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18015 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18016 | |
| 18017 | TestCompletionCallback callback; |
| 18018 | |
| 18019 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18020 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18021 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18022 | |
| 18023 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18024 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18025 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18026 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18027 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18028 | } |
| 18029 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18030 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18031 | ChunkedUploadDataStream upload_data_stream(0); |
| 18032 | |
| 18033 | HttpRequestInfo request; |
| 18034 | request.method = "POST"; |
| 18035 | request.url = GURL("http://www.foo.com/"); |
| 18036 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18037 | request.traffic_annotation = |
| 18038 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18039 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18040 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18041 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18042 | // Send headers successfully, but get an error while sending the body. |
| 18043 | MockWrite data_writes[] = { |
| 18044 | MockWrite("POST / HTTP/1.1\r\n" |
| 18045 | "Host: www.foo.com\r\n" |
| 18046 | "Connection: keep-alive\r\n" |
| 18047 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 18048 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 18049 | }; |
| 18050 | |
| 18051 | MockRead data_reads[] = { |
| 18052 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18053 | MockRead(SYNCHRONOUS, OK), |
| 18054 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18055 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18056 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18057 | |
| 18058 | TestCompletionCallback callback; |
| 18059 | |
| 18060 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18061 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18062 | |
| 18063 | base::RunLoop().RunUntilIdle(); |
| 18064 | upload_data_stream.AppendData("f", 1, false); |
| 18065 | |
| 18066 | base::RunLoop().RunUntilIdle(); |
| 18067 | upload_data_stream.AppendData("oo", 2, true); |
| 18068 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18069 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18070 | |
| 18071 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18072 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18073 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18074 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18075 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18076 | } |
| 18077 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18078 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 18079 | const std::string& accept_encoding, |
| 18080 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18081 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18082 | bool should_match) { |
| 18083 | HttpRequestInfo request; |
| 18084 | request.method = "GET"; |
| 18085 | request.url = GURL("http://www.foo.com/"); |
| 18086 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 18087 | accept_encoding); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18088 | request.traffic_annotation = |
| 18089 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18090 | |
| 18091 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 18092 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18093 | // Send headers successfully, but get an error while sending the body. |
| 18094 | MockWrite data_writes[] = { |
| 18095 | MockWrite("GET / HTTP/1.1\r\n" |
| 18096 | "Host: www.foo.com\r\n" |
| 18097 | "Connection: keep-alive\r\n" |
| 18098 | "Accept-Encoding: "), |
| 18099 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 18100 | }; |
| 18101 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18102 | std::string response_code = "200 OK"; |
| 18103 | std::string extra; |
| 18104 | if (!location.empty()) { |
| 18105 | response_code = "301 Redirect\r\nLocation: "; |
| 18106 | response_code.append(location); |
| 18107 | } |
| 18108 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18109 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18110 | MockRead("HTTP/1.0 "), |
| 18111 | MockRead(response_code.data()), |
| 18112 | MockRead("\r\nContent-Encoding: "), |
| 18113 | MockRead(content_encoding.data()), |
| 18114 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18115 | MockRead(SYNCHRONOUS, OK), |
| 18116 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18117 | StaticSocketDataProvider data(data_reads, data_writes); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18118 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 18119 | |
| 18120 | TestCompletionCallback callback; |
| 18121 | |
| 18122 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18123 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18124 | |
| 18125 | rv = callback.WaitForResult(); |
| 18126 | if (should_match) { |
| 18127 | EXPECT_THAT(rv, IsOk()); |
| 18128 | } else { |
| 18129 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 18130 | } |
| 18131 | } |
| 18132 | |
| 18133 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18134 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18135 | } |
| 18136 | |
| 18137 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18138 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 18139 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18140 | } |
| 18141 | |
| 18142 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 18143 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18144 | "", false); |
| 18145 | } |
| 18146 | |
| 18147 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 18148 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 18149 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18150 | } |
| 18151 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18152 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 18153 | ProxyConfig proxy_config; |
| 18154 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18155 | proxy_config.set_pac_mandatory(true); |
| 18156 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18157 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18158 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18159 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Bence Béky | 8f9d7d395 | 2017-10-09 19:58:04 | [diff] [blame] | 18160 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18161 | |
| 18162 | HttpRequestInfo request; |
| 18163 | request.method = "GET"; |
| 18164 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18165 | request.traffic_annotation = |
| 18166 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18167 | |
| 18168 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18169 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18170 | |
| 18171 | TestCompletionCallback callback; |
| 18172 | |
| 18173 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18174 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18175 | EXPECT_THAT(callback.WaitForResult(), |
| 18176 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18177 | } |
| 18178 | |
| 18179 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 18180 | ProxyConfig proxy_config; |
| 18181 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18182 | proxy_config.set_pac_mandatory(true); |
| 18183 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 18184 | new MockAsyncProxyResolverFactory(false); |
| 18185 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18186 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18187 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18188 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18189 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18190 | HttpRequestInfo request; |
| 18191 | request.method = "GET"; |
| 18192 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18193 | request.traffic_annotation = |
| 18194 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18195 | |
| 18196 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18197 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18198 | |
| 18199 | TestCompletionCallback callback; |
| 18200 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18201 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18202 | |
| 18203 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 18204 | ERR_FAILED, &resolver); |
| 18205 | EXPECT_THAT(callback.WaitForResult(), |
| 18206 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18207 | } |
| 18208 | |
| 18209 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18210 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18211 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18212 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18213 | session_deps_.enable_quic = false; |
| 18214 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18215 | |
| 18216 | HttpRequestInfo request; |
| 18217 | request.method = "GET"; |
| 18218 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18219 | request.traffic_annotation = |
| 18220 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18221 | |
| 18222 | TestCompletionCallback callback; |
| 18223 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18224 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18225 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18226 | |
| 18227 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 18228 | } |
| 18229 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18230 | //----------------------------------------------------------------------------- |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18231 | // Reporting tests |
| 18232 | |
| 18233 | #if BUILDFLAG(ENABLE_REPORTING) |
| 18234 | class HttpNetworkTransactionReportingTest : public HttpNetworkTransactionTest { |
| 18235 | protected: |
| 18236 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18237 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18238 | auto test_reporting_context = std::make_unique<TestReportingContext>( |
| 18239 | &clock_, &tick_clock_, ReportingPolicy()); |
| 18240 | test_reporting_context_ = test_reporting_context.get(); |
| 18241 | session_deps_.reporting_service = |
| 18242 | ReportingService::CreateForTesting(std::move(test_reporting_context)); |
| 18243 | } |
| 18244 | |
| 18245 | TestReportingContext* reporting_context() const { |
| 18246 | return test_reporting_context_; |
| 18247 | } |
| 18248 | |
| 18249 | void clear_reporting_service() { |
| 18250 | session_deps_.reporting_service.reset(); |
| 18251 | test_reporting_context_ = nullptr; |
| 18252 | } |
| 18253 | |
| 18254 | // Makes an HTTPS request that should install a valid Reporting policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18255 | void RequestPolicy(CertStatus cert_status = 0) { |
| 18256 | HttpRequestInfo request; |
| 18257 | request.method = "GET"; |
| 18258 | request.url = GURL(url_); |
| 18259 | request.traffic_annotation = |
| 18260 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18261 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18262 | MockWrite data_writes[] = { |
| 18263 | MockWrite("GET / HTTP/1.1\r\n" |
| 18264 | "Host: www.example.org\r\n" |
| 18265 | "Connection: keep-alive\r\n\r\n"), |
| 18266 | }; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18267 | MockRead data_reads[] = { |
| 18268 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18269 | MockRead("Report-To: {\"group\": \"nel\", \"max_age\": 86400, " |
| 18270 | "\"endpoints\": [{\"url\": " |
| 18271 | "\"https://www.example.org/upload/\"}]}\r\n"), |
| 18272 | MockRead("\r\n"), |
| 18273 | MockRead("hello world"), |
| 18274 | MockRead(SYNCHRONOUS, OK), |
| 18275 | }; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18276 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18277 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18278 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18279 | |
| 18280 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18281 | if (request.url.SchemeIsCryptographic()) { |
| 18282 | ssl.ssl_info.cert = |
| 18283 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18284 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18285 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18286 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18287 | } |
| 18288 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18289 | TestCompletionCallback callback; |
| 18290 | auto session = CreateSession(&session_deps_); |
| 18291 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18292 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18293 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18294 | } |
| 18295 | |
| 18296 | protected: |
| 18297 | std::string url_ = "https://www.example.org/"; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18298 | |
| 18299 | private: |
| 18300 | TestReportingContext* test_reporting_context_; |
| 18301 | }; |
| 18302 | |
| 18303 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18304 | DontProcessReportToHeaderNoService) { |
| 18305 | base::HistogramTester histograms; |
| 18306 | clear_reporting_service(); |
| 18307 | RequestPolicy(); |
| 18308 | histograms.ExpectBucketCount( |
| 18309 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18310 | ReportingHeaderParser::HeaderOutcome::DISCARDED_NO_REPORTING_SERVICE, 1); |
| 18311 | } |
| 18312 | |
| 18313 | TEST_F(HttpNetworkTransactionReportingTest, DontProcessReportToHeaderHttp) { |
| 18314 | base::HistogramTester histograms; |
| 18315 | url_ = "http://www.example.org/"; |
| 18316 | RequestPolicy(); |
| 18317 | histograms.ExpectBucketCount( |
| 18318 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18319 | ReportingHeaderParser::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18320 | } |
| 18321 | |
| 18322 | TEST_F(HttpNetworkTransactionReportingTest, ProcessReportToHeaderHttps) { |
| 18323 | RequestPolicy(); |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame^] | 18324 | ASSERT_EQ(1u, reporting_context()->cache()->GetEndpointCount()); |
| 18325 | const ReportingClient endpoint = |
| 18326 | reporting_context()->cache()->GetEndpointForTesting( |
| 18327 | url::Origin::Create(GURL("https://www.example.org/")), "nel", |
| 18328 | GURL("https://www.example.org/upload/")); |
| 18329 | EXPECT_TRUE(endpoint); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18330 | } |
| 18331 | |
| 18332 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18333 | DontProcessReportToHeaderInvalidHttps) { |
| 18334 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18335 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18336 | RequestPolicy(cert_status); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18337 | histograms.ExpectBucketCount( |
| 18338 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18339 | ReportingHeaderParser::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, 1); |
| 18340 | } |
| 18341 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 18342 | |
| 18343 | //----------------------------------------------------------------------------- |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18344 | // Network Error Logging tests |
| 18345 | |
| 18346 | #if BUILDFLAG(ENABLE_REPORTING) |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18347 | namespace { |
| 18348 | |
| 18349 | const char kUserAgent[] = "Mozilla/1.0"; |
| 18350 | const char kReferrer[] = "https://www.referrer.org/"; |
| 18351 | |
| 18352 | } // namespace |
| 18353 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18354 | class HttpNetworkTransactionNetworkErrorLoggingTest |
| 18355 | : public HttpNetworkTransactionTest { |
| 18356 | protected: |
| 18357 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18358 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18359 | auto network_error_logging_service = |
| 18360 | std::make_unique<TestNetworkErrorLoggingService>(); |
| 18361 | test_network_error_logging_service_ = network_error_logging_service.get(); |
| 18362 | session_deps_.network_error_logging_service = |
| 18363 | std::move(network_error_logging_service); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18364 | |
| 18365 | extra_headers_.SetHeader("User-Agent", kUserAgent); |
| 18366 | extra_headers_.SetHeader("Referer", kReferrer); |
| 18367 | |
| 18368 | request_.method = "GET"; |
| 18369 | request_.url = GURL(url_); |
| 18370 | request_.extra_headers = extra_headers_; |
| 18371 | request_.reporting_upload_depth = reporting_upload_depth_; |
| 18372 | request_.traffic_annotation = |
| 18373 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18374 | } |
| 18375 | |
| 18376 | TestNetworkErrorLoggingService* network_error_logging_service() const { |
| 18377 | return test_network_error_logging_service_; |
| 18378 | } |
| 18379 | |
| 18380 | void clear_network_error_logging_service() { |
| 18381 | session_deps_.network_error_logging_service.reset(); |
| 18382 | test_network_error_logging_service_ = nullptr; |
| 18383 | } |
| 18384 | |
| 18385 | // Makes an HTTPS request that should install a valid NEL policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18386 | void RequestPolicy(CertStatus cert_status = 0) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18387 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18388 | MockWrite data_writes[] = { |
| 18389 | MockWrite("GET / HTTP/1.1\r\n" |
| 18390 | "Host: www.example.org\r\n" |
| 18391 | "Connection: keep-alive\r\n"), |
| 18392 | MockWrite(ASYNC, extra_header_string.data(), |
| 18393 | extra_header_string.size()), |
| 18394 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18395 | MockRead data_reads[] = { |
| 18396 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18397 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 18398 | MockRead("\r\n"), |
| 18399 | MockRead("hello world"), |
| 18400 | MockRead(SYNCHRONOUS, OK), |
| 18401 | }; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18402 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18403 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18404 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18405 | |
| 18406 | SSLSocketDataProvider ssl(ASYNC, OK); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18407 | if (request_.url.SchemeIsCryptographic()) { |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18408 | ssl.ssl_info.cert = |
| 18409 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18410 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18411 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18412 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18413 | } |
| 18414 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18415 | TestCompletionCallback callback; |
| 18416 | auto session = CreateSession(&session_deps_); |
| 18417 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18418 | int rv = trans.Start(&request_, callback.callback(), NetLogWithSource()); |
| 18419 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18420 | |
| 18421 | std::string response_data; |
| 18422 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 18423 | EXPECT_EQ("hello world", response_data); |
| 18424 | } |
| 18425 | |
| 18426 | void CheckReport(size_t index, |
| 18427 | int status_code, |
| 18428 | int error_type, |
| 18429 | IPAddress server_ip = IPAddress::IPv4Localhost()) { |
| 18430 | ASSERT_LT(index, network_error_logging_service()->errors().size()); |
| 18431 | |
| 18432 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18433 | network_error_logging_service()->errors()[index]; |
| 18434 | EXPECT_EQ(url_, error.uri); |
| 18435 | EXPECT_EQ(kReferrer, error.referrer); |
| 18436 | EXPECT_EQ(kUserAgent, error.user_agent); |
| 18437 | EXPECT_EQ(server_ip, error.server_ip); |
| 18438 | EXPECT_EQ("http/1.1", error.protocol); |
| 18439 | EXPECT_EQ("GET", error.method); |
| 18440 | EXPECT_EQ(status_code, error.status_code); |
| 18441 | EXPECT_EQ(error_type, error.type); |
| 18442 | EXPECT_EQ(0, error.reporting_upload_depth); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18443 | } |
| 18444 | |
| 18445 | protected: |
| 18446 | std::string url_ = "https://www.example.org/"; |
| 18447 | CertStatus cert_status_ = 0; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18448 | HttpRequestInfo request_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18449 | HttpRequestHeaders extra_headers_; |
| 18450 | int reporting_upload_depth_ = 0; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18451 | |
| 18452 | private: |
| 18453 | TestNetworkErrorLoggingService* test_network_error_logging_service_; |
| 18454 | }; |
| 18455 | |
| 18456 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18457 | DontProcessNelHeaderNoService) { |
| 18458 | base::HistogramTester histograms; |
| 18459 | clear_network_error_logging_service(); |
| 18460 | RequestPolicy(); |
| 18461 | histograms.ExpectBucketCount( |
| 18462 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18463 | NetworkErrorLoggingService::HeaderOutcome:: |
| 18464 | DISCARDED_NO_NETWORK_ERROR_LOGGING_SERVICE, |
| 18465 | 1); |
| 18466 | } |
| 18467 | |
| 18468 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18469 | DontProcessNelHeaderHttp) { |
| 18470 | base::HistogramTester histograms; |
| 18471 | url_ = "http://www.example.org/"; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18472 | request_.url = GURL(url_); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18473 | RequestPolicy(); |
| 18474 | histograms.ExpectBucketCount( |
| 18475 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18476 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18477 | } |
| 18478 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 18479 | // Don't set NEL policies received on a proxied connection. |
| 18480 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18481 | DontProcessNelHeaderProxy) { |
| 18482 | session_deps_.proxy_resolution_service = |
| 18483 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18484 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18485 | BoundTestNetLog log; |
| 18486 | session_deps_.net_log = log.bound().net_log(); |
| 18487 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18488 | |
| 18489 | HttpRequestInfo request; |
| 18490 | request.method = "GET"; |
| 18491 | request.url = GURL("https://www.example.org/"); |
| 18492 | request.traffic_annotation = |
| 18493 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18494 | |
| 18495 | // Since we have proxy, should try to establish tunnel. |
| 18496 | MockWrite data_writes1[] = { |
| 18497 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 18498 | "Host: www.example.org:443\r\n" |
| 18499 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 18500 | |
| 18501 | MockWrite("GET / HTTP/1.1\r\n" |
| 18502 | "Host: www.example.org\r\n" |
| 18503 | "Connection: keep-alive\r\n\r\n"), |
| 18504 | }; |
| 18505 | |
| 18506 | MockRead data_reads1[] = { |
| 18507 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 18508 | |
| 18509 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 18510 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 18511 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18512 | MockRead("Content-Length: 100\r\n\r\n"), |
| 18513 | MockRead(SYNCHRONOUS, OK), |
| 18514 | }; |
| 18515 | |
| 18516 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18517 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18518 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18519 | ssl.ssl_info.cert = |
| 18520 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18521 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 18522 | ssl.ssl_info.cert_status = 0; |
| 18523 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18524 | |
| 18525 | TestCompletionCallback callback1; |
| 18526 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18527 | |
| 18528 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
| 18529 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18530 | |
| 18531 | rv = callback1.WaitForResult(); |
| 18532 | EXPECT_THAT(rv, IsOk()); |
| 18533 | |
| 18534 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 18535 | ASSERT_TRUE(response); |
| 18536 | EXPECT_EQ(200, response->headers->response_code()); |
| 18537 | EXPECT_TRUE(response->was_fetched_via_proxy); |
| 18538 | |
| 18539 | // No NEL header was set. |
| 18540 | EXPECT_EQ(0u, network_error_logging_service()->headers().size()); |
| 18541 | } |
| 18542 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18543 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ProcessNelHeaderHttps) { |
| 18544 | RequestPolicy(); |
| 18545 | ASSERT_EQ(1u, network_error_logging_service()->headers().size()); |
| 18546 | const auto& header = network_error_logging_service()->headers()[0]; |
| 18547 | EXPECT_EQ(url::Origin::Create(GURL("https://www.example.org/")), |
| 18548 | header.origin); |
| 18549 | EXPECT_EQ(IPAddress::IPv4Localhost(), header.received_ip_address); |
| 18550 | EXPECT_EQ("{\"report_to\": \"nel\", \"max_age\": 86400}", header.value); |
| 18551 | } |
| 18552 | |
| 18553 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18554 | DontProcessNelHeaderInvalidHttps) { |
| 18555 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18556 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18557 | RequestPolicy(cert_status); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18558 | histograms.ExpectBucketCount( |
| 18559 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18560 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, |
| 18561 | 1); |
| 18562 | } |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18563 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18564 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, CreateReportSuccess) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18565 | RequestPolicy(); |
| 18566 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18567 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 18568 | } |
| 18569 | |
| 18570 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18571 | CreateReportErrorAfterStart) { |
| 18572 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18573 | auto trans = |
| 18574 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18575 | |
| 18576 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
| 18577 | StaticSocketDataProvider data; |
| 18578 | data.set_connect_data(mock_connect); |
| 18579 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18580 | |
| 18581 | TestCompletionCallback callback; |
| 18582 | |
| 18583 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18584 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 18585 | |
| 18586 | trans.reset(); |
| 18587 | |
| 18588 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18589 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 18590 | IPAddress() /* server_ip */); |
| 18591 | } |
| 18592 | |
| 18593 | // Same as above except the error is ASYNC |
| 18594 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18595 | CreateReportErrorAfterStartAsync) { |
| 18596 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18597 | auto trans = |
| 18598 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18599 | |
| 18600 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
| 18601 | StaticSocketDataProvider data; |
| 18602 | data.set_connect_data(mock_connect); |
| 18603 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18604 | |
| 18605 | TestCompletionCallback callback; |
| 18606 | |
| 18607 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18608 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 18609 | |
| 18610 | trans.reset(); |
| 18611 | |
| 18612 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18613 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 18614 | IPAddress() /* server_ip */); |
| 18615 | } |
| 18616 | |
| 18617 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18618 | CreateReportReadBodyError) { |
| 18619 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18620 | MockWrite data_writes[] = { |
| 18621 | MockWrite("GET / HTTP/1.1\r\n" |
| 18622 | "Host: www.example.org\r\n" |
| 18623 | "Connection: keep-alive\r\n"), |
| 18624 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18625 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18626 | MockRead data_reads[] = { |
| 18627 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18628 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 18629 | MockRead("hello world"), |
| 18630 | MockRead(SYNCHRONOUS, OK), |
| 18631 | }; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18632 | |
| 18633 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18634 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 18635 | |
| 18636 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18637 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18638 | |
| 18639 | // Log start time |
| 18640 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18641 | |
| 18642 | TestCompletionCallback callback; |
| 18643 | auto session = CreateSession(&session_deps_); |
| 18644 | auto trans = |
| 18645 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18646 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18647 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18648 | |
| 18649 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18650 | ASSERT_TRUE(response); |
| 18651 | |
| 18652 | EXPECT_TRUE(response->headers); |
| 18653 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 18654 | |
| 18655 | std::string response_data; |
| 18656 | rv = ReadTransaction(trans.get(), &response_data); |
| 18657 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 18658 | |
| 18659 | trans.reset(); |
| 18660 | |
| 18661 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18662 | |
| 18663 | CheckReport(0 /* index */, 200 /* status_code */, |
| 18664 | ERR_CONTENT_LENGTH_MISMATCH); |
| 18665 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18666 | network_error_logging_service()->errors()[0]; |
| 18667 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 18668 | } |
| 18669 | |
| 18670 | // Same as above except the final read is ASYNC. |
| 18671 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18672 | CreateReportReadBodyErrorAsync) { |
| 18673 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18674 | MockWrite data_writes[] = { |
| 18675 | MockWrite("GET / HTTP/1.1\r\n" |
| 18676 | "Host: www.example.org\r\n" |
| 18677 | "Connection: keep-alive\r\n"), |
| 18678 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18679 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18680 | MockRead data_reads[] = { |
| 18681 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18682 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 18683 | MockRead("hello world"), |
| 18684 | MockRead(ASYNC, OK), |
| 18685 | }; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18686 | |
| 18687 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18688 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 18689 | |
| 18690 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18691 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18692 | |
| 18693 | // Log start time |
| 18694 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18695 | |
| 18696 | TestCompletionCallback callback; |
| 18697 | auto session = CreateSession(&session_deps_); |
| 18698 | auto trans = |
| 18699 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18700 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18701 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18702 | |
| 18703 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18704 | ASSERT_TRUE(response); |
| 18705 | |
| 18706 | EXPECT_TRUE(response->headers); |
| 18707 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 18708 | |
| 18709 | std::string response_data; |
| 18710 | rv = ReadTransaction(trans.get(), &response_data); |
| 18711 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 18712 | |
| 18713 | trans.reset(); |
| 18714 | |
| 18715 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18716 | |
| 18717 | CheckReport(0 /* index */, 200 /* status_code */, |
| 18718 | ERR_CONTENT_LENGTH_MISMATCH); |
| 18719 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18720 | network_error_logging_service()->errors()[0]; |
| 18721 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 18722 | } |
| 18723 | |
| 18724 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18725 | CreateReportRestartWithAuth) { |
| 18726 | std::string extra_header_string = extra_headers_.ToString(); |
| 18727 | static const base::TimeDelta kSleepDuration = |
| 18728 | base::TimeDelta::FromMilliseconds(10); |
| 18729 | |
| 18730 | MockWrite data_writes1[] = { |
| 18731 | MockWrite("GET / HTTP/1.1\r\n" |
| 18732 | "Host: www.example.org\r\n" |
| 18733 | "Connection: keep-alive\r\n"), |
| 18734 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18735 | }; |
| 18736 | |
| 18737 | MockRead data_reads1[] = { |
| 18738 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 18739 | // Give a couple authenticate options (only the middle one is actually |
| 18740 | // supported). |
| 18741 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 18742 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 18743 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 18744 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18745 | // Large content-length -- won't matter, as connection will be reset. |
| 18746 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 18747 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 18748 | }; |
| 18749 | |
| 18750 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18751 | // be issuing -- the final header line contains the credentials. |
| 18752 | MockWrite data_writes2[] = { |
| 18753 | MockWrite("GET / HTTP/1.1\r\n" |
| 18754 | "Host: www.example.org\r\n" |
| 18755 | "Connection: keep-alive\r\n" |
| 18756 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 18757 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18758 | }; |
| 18759 | |
| 18760 | // Lastly, the server responds with the actual content. |
| 18761 | MockRead data_reads2[] = { |
| 18762 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 18763 | MockRead("hello world"), |
| 18764 | MockRead(SYNCHRONOUS, OK), |
| 18765 | }; |
| 18766 | |
| 18767 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18768 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 18769 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18770 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18771 | |
| 18772 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18773 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18774 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18775 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18776 | |
| 18777 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18778 | base::TimeTicks restart_time; |
| 18779 | |
| 18780 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18781 | auto trans = |
| 18782 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18783 | |
| 18784 | TestCompletionCallback callback1; |
| 18785 | |
| 18786 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18787 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18788 | |
| 18789 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18790 | |
| 18791 | TestCompletionCallback callback2; |
| 18792 | |
| 18793 | // Wait 10 ms then restart with auth |
| 18794 | FastForwardBy(kSleepDuration); |
| 18795 | restart_time = base::TimeTicks::Now(); |
| 18796 | rv = |
| 18797 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 18798 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18799 | |
| 18800 | std::string response_data; |
| 18801 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 18802 | EXPECT_EQ("hello world", response_data); |
| 18803 | |
| 18804 | trans.reset(); |
| 18805 | |
| 18806 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 18807 | // retry. Note that we don't report the error draining the body, as the first |
| 18808 | // request already generated a report for the auth challenge. |
| 18809 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 18810 | |
| 18811 | // Check error report contents |
| 18812 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 18813 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 18814 | |
| 18815 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 18816 | network_error_logging_service()->errors()[0]; |
| 18817 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 18818 | network_error_logging_service()->errors()[1]; |
| 18819 | |
| 18820 | // Sanity-check elapsed time values |
| 18821 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 18822 | // Check that the start time is refreshed when restarting with auth. |
| 18823 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 18824 | } |
| 18825 | |
| 18826 | // Same as above, except draining the body before restarting fails |
| 18827 | // asynchronously. |
| 18828 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18829 | CreateReportRestartWithAuthAsync) { |
| 18830 | std::string extra_header_string = extra_headers_.ToString(); |
| 18831 | static const base::TimeDelta kSleepDuration = |
| 18832 | base::TimeDelta::FromMilliseconds(10); |
| 18833 | |
| 18834 | MockWrite data_writes1[] = { |
| 18835 | MockWrite("GET / HTTP/1.1\r\n" |
| 18836 | "Host: www.example.org\r\n" |
| 18837 | "Connection: keep-alive\r\n"), |
| 18838 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18839 | }; |
| 18840 | |
| 18841 | MockRead data_reads1[] = { |
| 18842 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 18843 | // Give a couple authenticate options (only the middle one is actually |
| 18844 | // supported). |
| 18845 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 18846 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 18847 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 18848 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18849 | // Large content-length -- won't matter, as connection will be reset. |
| 18850 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 18851 | MockRead(ASYNC, ERR_FAILED), |
| 18852 | }; |
| 18853 | |
| 18854 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18855 | // be issuing -- the final header line contains the credentials. |
| 18856 | MockWrite data_writes2[] = { |
| 18857 | MockWrite("GET / HTTP/1.1\r\n" |
| 18858 | "Host: www.example.org\r\n" |
| 18859 | "Connection: keep-alive\r\n" |
| 18860 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 18861 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18862 | }; |
| 18863 | |
| 18864 | // Lastly, the server responds with the actual content. |
| 18865 | MockRead data_reads2[] = { |
| 18866 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 18867 | MockRead("hello world"), |
| 18868 | MockRead(SYNCHRONOUS, OK), |
| 18869 | }; |
| 18870 | |
| 18871 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18872 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 18873 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18874 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18875 | |
| 18876 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18877 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18878 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18879 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18880 | |
| 18881 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18882 | base::TimeTicks restart_time; |
| 18883 | |
| 18884 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18885 | auto trans = |
| 18886 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18887 | |
| 18888 | TestCompletionCallback callback1; |
| 18889 | |
| 18890 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18891 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18892 | |
| 18893 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18894 | |
| 18895 | TestCompletionCallback callback2; |
| 18896 | |
| 18897 | // Wait 10 ms then restart with auth |
| 18898 | FastForwardBy(kSleepDuration); |
| 18899 | restart_time = base::TimeTicks::Now(); |
| 18900 | rv = |
| 18901 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 18902 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18903 | |
| 18904 | std::string response_data; |
| 18905 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 18906 | EXPECT_EQ("hello world", response_data); |
| 18907 | |
| 18908 | trans.reset(); |
| 18909 | |
| 18910 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 18911 | // retry. Note that we don't report the error draining the body, as the first |
| 18912 | // request already generated a report for the auth challenge. |
| 18913 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 18914 | |
| 18915 | // Check error report contents |
| 18916 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 18917 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 18918 | |
| 18919 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 18920 | network_error_logging_service()->errors()[0]; |
| 18921 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 18922 | network_error_logging_service()->errors()[1]; |
| 18923 | |
| 18924 | // Sanity-check elapsed time values |
| 18925 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 18926 | // Check that the start time is refreshed when restarting with auth. |
| 18927 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 18928 | } |
| 18929 | |
| 18930 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18931 | CreateReportRetryKeepAliveConnectionReset) { |
| 18932 | std::string extra_header_string = extra_headers_.ToString(); |
| 18933 | MockWrite data_writes1[] = { |
| 18934 | MockWrite("GET / HTTP/1.1\r\n" |
| 18935 | "Host: www.example.org\r\n" |
| 18936 | "Connection: keep-alive\r\n"), |
| 18937 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18938 | MockWrite("GET / HTTP/1.1\r\n" |
| 18939 | "Host: www.example.org\r\n" |
| 18940 | "Connection: keep-alive\r\n"), |
| 18941 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18942 | }; |
| 18943 | |
| 18944 | MockRead data_reads1[] = { |
| 18945 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 18946 | MockRead("hello"), |
| 18947 | // Connection is reset |
| 18948 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 18949 | }; |
| 18950 | |
| 18951 | // Successful retry |
| 18952 | MockRead data_reads2[] = { |
| 18953 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 18954 | MockRead("world"), |
| 18955 | MockRead(ASYNC, OK), |
| 18956 | }; |
| 18957 | |
| 18958 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18959 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 18960 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18961 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18962 | |
| 18963 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18964 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18965 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18966 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18967 | |
| 18968 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18969 | auto trans1 = |
| 18970 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18971 | |
| 18972 | TestCompletionCallback callback1; |
| 18973 | |
| 18974 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18975 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18976 | |
| 18977 | std::string response_data; |
| 18978 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 18979 | EXPECT_EQ("hello", response_data); |
| 18980 | |
| 18981 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18982 | |
| 18983 | auto trans2 = |
| 18984 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18985 | |
| 18986 | TestCompletionCallback callback2; |
| 18987 | |
| 18988 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 18989 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18990 | |
| 18991 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 18992 | EXPECT_EQ("world", response_data); |
| 18993 | |
| 18994 | trans1.reset(); |
| 18995 | trans2.reset(); |
| 18996 | |
| 18997 | // One OK report from first request, then a ERR_CONNECTION_RESET report from |
| 18998 | // the second request, then an OK report from the successful retry. |
| 18999 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19000 | |
| 19001 | // Check error report contents |
| 19002 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19003 | CheckReport(1 /* index */, 0 /* status_code */, ERR_CONNECTION_RESET); |
| 19004 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 19005 | } |
| 19006 | |
| 19007 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19008 | CreateReportRetryKeepAlive408) { |
| 19009 | std::string extra_header_string = extra_headers_.ToString(); |
| 19010 | MockWrite data_writes1[] = { |
| 19011 | MockWrite("GET / HTTP/1.1\r\n" |
| 19012 | "Host: www.example.org\r\n" |
| 19013 | "Connection: keep-alive\r\n"), |
| 19014 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19015 | MockWrite("GET / HTTP/1.1\r\n" |
| 19016 | "Host: www.example.org\r\n" |
| 19017 | "Connection: keep-alive\r\n"), |
| 19018 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19019 | }; |
| 19020 | |
| 19021 | MockRead data_reads1[] = { |
| 19022 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19023 | MockRead("hello"), |
| 19024 | // 408 Request Timeout |
| 19025 | MockRead(SYNCHRONOUS, |
| 19026 | "HTTP/1.1 408 Request Timeout\r\n" |
| 19027 | "Connection: Keep-Alive\r\n" |
| 19028 | "Content-Length: 6\r\n\r\n" |
| 19029 | "Pickle"), |
| 19030 | }; |
| 19031 | |
| 19032 | // Successful retry |
| 19033 | MockRead data_reads2[] = { |
| 19034 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19035 | MockRead("world"), |
| 19036 | MockRead(ASYNC, OK), |
| 19037 | }; |
| 19038 | |
| 19039 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19040 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 19041 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19042 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19043 | |
| 19044 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 19045 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 19046 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 19047 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 19048 | |
| 19049 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19050 | auto trans1 = |
| 19051 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19052 | |
| 19053 | TestCompletionCallback callback1; |
| 19054 | |
| 19055 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 19056 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19057 | |
| 19058 | std::string response_data; |
| 19059 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19060 | EXPECT_EQ("hello", response_data); |
| 19061 | |
| 19062 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19063 | |
| 19064 | auto trans2 = |
| 19065 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19066 | |
| 19067 | TestCompletionCallback callback2; |
| 19068 | |
| 19069 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 19070 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19071 | |
| 19072 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19073 | EXPECT_EQ("world", response_data); |
| 19074 | |
| 19075 | trans1.reset(); |
| 19076 | trans2.reset(); |
| 19077 | |
| 19078 | // One 200 report from first request, then a 408 report from |
| 19079 | // the second request, then a 200 report from the successful retry. |
| 19080 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19081 | |
| 19082 | // Check error report contents |
| 19083 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19084 | CheckReport(1 /* index */, 408 /* status_code */, OK); |
| 19085 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 19086 | } |
| 19087 | |
| 19088 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19089 | CreateReportRetry421WithoutConnectionPooling) { |
| 19090 | // Two hosts resolve to the same IP address. |
| 19091 | const std::string ip_addr = "1.2.3.4"; |
| 19092 | IPAddress ip; |
| 19093 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 19094 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 19095 | |
| 19096 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
| 19097 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 19098 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 19099 | |
| 19100 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19101 | |
| 19102 | // Two requests on the first connection. |
| 19103 | spdy::SpdySerializedFrame req1( |
| 19104 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 19105 | spdy_util_.UpdateWithStreamDestruction(1); |
| 19106 | spdy::SpdySerializedFrame req2( |
| 19107 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 19108 | spdy::SpdySerializedFrame rst( |
| 19109 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
| 19110 | MockWrite writes1[] = { |
| 19111 | CreateMockWrite(req1, 0), |
| 19112 | CreateMockWrite(req2, 3), |
| 19113 | CreateMockWrite(rst, 6), |
| 19114 | }; |
| 19115 | |
| 19116 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 19117 | spdy::SpdySerializedFrame resp1( |
| 19118 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 19119 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 19120 | spdy::SpdyHeaderBlock response_headers; |
| 19121 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 19122 | spdy::SpdySerializedFrame resp2( |
| 19123 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 19124 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 19125 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 19126 | |
| 19127 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 19128 | SequencedSocketData data1(connect1, reads1, writes1); |
| 19129 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19130 | |
| 19131 | AddSSLSocketData(); |
| 19132 | |
| 19133 | // Retry the second request on a second connection. |
| 19134 | SpdyTestUtil spdy_util2; |
| 19135 | spdy::SpdySerializedFrame req3( |
| 19136 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 19137 | MockWrite writes2[] = { |
| 19138 | CreateMockWrite(req3, 0), |
| 19139 | }; |
| 19140 | |
| 19141 | spdy::SpdySerializedFrame resp3( |
| 19142 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 19143 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 19144 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 19145 | MockRead(ASYNC, 0, 3)}; |
| 19146 | |
| 19147 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 19148 | SequencedSocketData data2(connect2, reads2, writes2); |
| 19149 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19150 | |
| 19151 | AddSSLSocketData(); |
| 19152 | |
| 19153 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 19154 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 19155 | HostPortPair("mail.example.com", 443), base::nullopt); |
| 19156 | EXPECT_THAT(rv, IsOk()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19157 | |
| 19158 | HttpRequestInfo request1; |
| 19159 | request1.method = "GET"; |
| 19160 | request1.url = GURL("https://www.example.org/"); |
| 19161 | request1.load_flags = 0; |
| 19162 | request1.traffic_annotation = |
| 19163 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19164 | auto trans1 = |
| 19165 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19166 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 19167 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19168 | rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 19169 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19170 | |
| 19171 | const HttpResponseInfo* response = trans1->GetResponseInfo(); |
| 19172 | ASSERT_TRUE(response); |
| 19173 | ASSERT_TRUE(response->headers); |
| 19174 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19175 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19176 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19177 | std::string response_data; |
| 19178 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19179 | EXPECT_EQ("hello!", response_data); |
| 19180 | |
| 19181 | trans1.reset(); |
| 19182 | |
| 19183 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19184 | |
| 19185 | HttpRequestInfo request2; |
| 19186 | request2.method = "GET"; |
| 19187 | request2.url = GURL("https://mail.example.org/"); |
| 19188 | request2.load_flags = 0; |
| 19189 | request2.traffic_annotation = |
| 19190 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19191 | auto trans2 = |
| 19192 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19193 | |
| 19194 | BoundTestNetLog log; |
| 19195 | rv = trans2->Start(&request2, callback.callback(), log.bound()); |
| 19196 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19197 | |
| 19198 | response = trans2->GetResponseInfo(); |
| 19199 | ASSERT_TRUE(response); |
| 19200 | ASSERT_TRUE(response->headers); |
| 19201 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19202 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19203 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19204 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19205 | EXPECT_EQ("hello!", response_data); |
| 19206 | |
| 19207 | trans2.reset(); |
| 19208 | |
| 19209 | // One 200 report from the first request, then a 421 report from the |
| 19210 | // second request, then a 200 report from the successful retry. |
| 19211 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19212 | |
| 19213 | // Check error report contents |
| 19214 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 19215 | network_error_logging_service()->errors()[0]; |
| 19216 | EXPECT_EQ(GURL("https://www.example.org/"), error1.uri); |
| 19217 | EXPECT_TRUE(error1.referrer.is_empty()); |
| 19218 | EXPECT_EQ("", error1.user_agent); |
| 19219 | EXPECT_EQ(ip, error1.server_ip); |
| 19220 | EXPECT_EQ("h2", error1.protocol); |
| 19221 | EXPECT_EQ("GET", error1.method); |
| 19222 | EXPECT_EQ(200, error1.status_code); |
| 19223 | EXPECT_EQ(OK, error1.type); |
| 19224 | EXPECT_EQ(0, error1.reporting_upload_depth); |
| 19225 | |
| 19226 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 19227 | network_error_logging_service()->errors()[1]; |
| 19228 | EXPECT_EQ(GURL("https://mail.example.org/"), error2.uri); |
| 19229 | EXPECT_TRUE(error2.referrer.is_empty()); |
| 19230 | EXPECT_EQ("", error2.user_agent); |
| 19231 | EXPECT_EQ(ip, error2.server_ip); |
| 19232 | EXPECT_EQ("h2", error2.protocol); |
| 19233 | EXPECT_EQ("GET", error2.method); |
| 19234 | EXPECT_EQ(421, error2.status_code); |
| 19235 | EXPECT_EQ(OK, error2.type); |
| 19236 | EXPECT_EQ(0, error2.reporting_upload_depth); |
| 19237 | |
| 19238 | const NetworkErrorLoggingService::RequestDetails& error3 = |
| 19239 | network_error_logging_service()->errors()[2]; |
| 19240 | EXPECT_EQ(GURL("https://mail.example.org/"), error3.uri); |
| 19241 | EXPECT_TRUE(error3.referrer.is_empty()); |
| 19242 | EXPECT_EQ("", error3.user_agent); |
| 19243 | EXPECT_EQ(ip, error3.server_ip); |
| 19244 | EXPECT_EQ("h2", error3.protocol); |
| 19245 | EXPECT_EQ("GET", error3.method); |
| 19246 | EXPECT_EQ(200, error3.status_code); |
| 19247 | EXPECT_EQ(OK, error3.type); |
| 19248 | EXPECT_EQ(0, error3.reporting_upload_depth); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19249 | } |
| 19250 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19251 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19252 | CreateReportCancelAfterStart) { |
| 19253 | StaticSocketDataProvider data; |
| 19254 | data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING)); |
| 19255 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19256 | |
| 19257 | TestCompletionCallback callback; |
| 19258 | auto session = CreateSession(&session_deps_); |
| 19259 | auto trans = |
| 19260 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19261 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19262 | EXPECT_EQ(rv, ERR_IO_PENDING); |
| 19263 | |
| 19264 | // Cancel after start. |
| 19265 | trans.reset(); |
| 19266 | |
| 19267 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19268 | CheckReport(0 /* index */, 0 /* status_code */, ERR_ABORTED, |
| 19269 | IPAddress() /* server_ip */); |
| 19270 | } |
| 19271 | |
| 19272 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19273 | CreateReportCancelBeforeReadingBody) { |
| 19274 | std::string extra_header_string = extra_headers_.ToString(); |
| 19275 | MockWrite data_writes[] = { |
| 19276 | MockWrite("GET / HTTP/1.1\r\n" |
| 19277 | "Host: www.example.org\r\n" |
| 19278 | "Connection: keep-alive\r\n"), |
| 19279 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19280 | }; |
| 19281 | MockRead data_reads[] = { |
| 19282 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 19283 | MockRead("Content-Length: 100\r\n\r\n"), // Body is never read. |
| 19284 | }; |
| 19285 | |
| 19286 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19287 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19288 | |
| 19289 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19290 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19291 | |
| 19292 | TestCompletionCallback callback; |
| 19293 | auto session = CreateSession(&session_deps_); |
| 19294 | auto trans = |
| 19295 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19296 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19297 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19298 | |
| 19299 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19300 | ASSERT_TRUE(response); |
| 19301 | |
| 19302 | EXPECT_TRUE(response->headers); |
| 19303 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 19304 | |
| 19305 | // Cancel before reading the body. |
| 19306 | trans.reset(); |
| 19307 | |
| 19308 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19309 | CheckReport(0 /* index */, 200 /* status_code */, ERR_ABORTED); |
| 19310 | } |
| 19311 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19312 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportHttp) { |
| 19313 | base::HistogramTester histograms; |
| 19314 | RequestPolicy(); |
| 19315 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19316 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19317 | |
| 19318 | // Make HTTP request |
| 19319 | std::string extra_header_string = extra_headers_.ToString(); |
| 19320 | MockRead data_reads[] = { |
| 19321 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 19322 | MockRead("hello world"), |
| 19323 | MockRead(SYNCHRONOUS, OK), |
| 19324 | }; |
| 19325 | MockWrite data_writes[] = { |
| 19326 | MockWrite("GET / HTTP/1.1\r\n" |
| 19327 | "Host: www.example.org\r\n" |
| 19328 | "Connection: keep-alive\r\n"), |
| 19329 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19330 | }; |
| 19331 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19332 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19333 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19334 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19335 | // Insecure url |
| 19336 | url_ = "http://www.example.org/"; |
| 19337 | request_.url = GURL(url_); |
| 19338 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19339 | TestCompletionCallback callback; |
| 19340 | auto session = CreateSession(&session_deps_); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19341 | auto trans = |
| 19342 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19343 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19344 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19345 | |
| 19346 | std::string response_data; |
| 19347 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19348 | EXPECT_EQ("hello world", response_data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19349 | |
| 19350 | // Insecure request does not generate a report |
| 19351 | histograms.ExpectBucketCount( |
| 19352 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
Tsuyoshi Horo | 0b04223 | 2019-03-06 01:11:05 | [diff] [blame] | 19353 | NetworkErrorLoggingService::RequestOutcome::kDiscardedInsecureOrigin, 1); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19354 | |
| 19355 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19356 | } |
| 19357 | |
| 19358 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19359 | DontCreateReportHttpError) { |
| 19360 | base::HistogramTester histograms; |
| 19361 | RequestPolicy(); |
| 19362 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19363 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19364 | |
| 19365 | // Make HTTP request that fails |
| 19366 | MockRead data_reads[] = { |
| 19367 | MockRead("hello world"), |
| 19368 | MockRead(SYNCHRONOUS, OK), |
| 19369 | }; |
| 19370 | |
| 19371 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
| 19372 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19373 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19374 | url_ = "http://www.originwithoutpolicy.com:2000/"; |
| 19375 | request_.url = GURL(url_); |
| 19376 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19377 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19378 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19379 | auto trans = |
| 19380 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19381 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19382 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19383 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 19384 | |
| 19385 | // Insecure request does not generate a report, regardless of existence of a |
| 19386 | // policy for the origin. |
| 19387 | histograms.ExpectBucketCount( |
| 19388 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
Tsuyoshi Horo | 0b04223 | 2019-03-06 01:11:05 | [diff] [blame] | 19389 | NetworkErrorLoggingService::RequestOutcome::kDiscardedInsecureOrigin, 1); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19390 | |
| 19391 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19392 | } |
| 19393 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 19394 | // Don't report on proxy auth challenges, don't report if connecting through a |
| 19395 | // proxy. |
| 19396 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportProxy) { |
| 19397 | HttpRequestInfo request; |
| 19398 | request.method = "GET"; |
| 19399 | request.url = GURL("https://www.example.org/"); |
| 19400 | request.traffic_annotation = |
| 19401 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19402 | |
| 19403 | // Configure against proxy server "myproxy:70". |
| 19404 | session_deps_.proxy_resolution_service = |
| 19405 | ProxyResolutionService::CreateFixedFromPacResult( |
| 19406 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19407 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19408 | |
| 19409 | // Since we have proxy, should try to establish tunnel. |
| 19410 | MockWrite data_writes1[] = { |
| 19411 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19412 | "Host: www.example.org:443\r\n" |
| 19413 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 19414 | }; |
| 19415 | |
| 19416 | // The proxy responds to the connect with a 407, using a non-persistent |
| 19417 | // connection. |
| 19418 | MockRead data_reads1[] = { |
| 19419 | // No credentials. |
| 19420 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 19421 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 19422 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 19423 | }; |
| 19424 | |
| 19425 | MockWrite data_writes2[] = { |
| 19426 | // After calling trans->RestartWithAuth(), this is the request we should |
| 19427 | // be issuing -- the final header line contains the credentials. |
| 19428 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19429 | "Host: www.example.org:443\r\n" |
| 19430 | "Proxy-Connection: keep-alive\r\n" |
| 19431 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 19432 | |
| 19433 | MockWrite("GET / HTTP/1.1\r\n" |
| 19434 | "Host: www.example.org\r\n" |
| 19435 | "Connection: keep-alive\r\n\r\n"), |
| 19436 | }; |
| 19437 | |
| 19438 | MockRead data_reads2[] = { |
| 19439 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 19440 | |
| 19441 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19442 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 19443 | MockRead("Content-Length: 5\r\n\r\n"), |
| 19444 | MockRead(SYNCHRONOUS, "hello"), |
| 19445 | }; |
| 19446 | |
| 19447 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19448 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19449 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 19450 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19451 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19452 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19453 | |
| 19454 | TestCompletionCallback callback1; |
| 19455 | |
| 19456 | auto trans = |
| 19457 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19458 | |
| 19459 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
| 19460 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19461 | |
| 19462 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19463 | EXPECT_EQ(407, response->headers->response_code()); |
| 19464 | |
| 19465 | std::string response_data; |
| 19466 | rv = ReadTransaction(trans.get(), &response_data); |
| 19467 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
| 19468 | |
| 19469 | // No NEL report is generated for the 407. |
| 19470 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 19471 | |
| 19472 | TestCompletionCallback callback2; |
| 19473 | |
| 19474 | rv = |
| 19475 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 19476 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19477 | |
| 19478 | response = trans->GetResponseInfo(); |
| 19479 | EXPECT_EQ(200, response->headers->response_code()); |
| 19480 | |
| 19481 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19482 | EXPECT_EQ("hello", response_data); |
| 19483 | |
| 19484 | trans.reset(); |
| 19485 | |
| 19486 | // No NEL report is generated because we are behind a proxy. |
| 19487 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 19488 | } |
| 19489 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19490 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19491 | ReportContainsUploadDepth) { |
| 19492 | reporting_upload_depth_ = 7; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19493 | request_.reporting_upload_depth = reporting_upload_depth_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19494 | RequestPolicy(); |
| 19495 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19496 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19497 | network_error_logging_service()->errors()[0]; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19498 | EXPECT_EQ(7, error.reporting_upload_depth); |
| 19499 | } |
| 19500 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19501 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ReportElapsedTime) { |
| 19502 | std::string extra_header_string = extra_headers_.ToString(); |
| 19503 | static const base::TimeDelta kSleepDuration = |
| 19504 | base::TimeDelta::FromMilliseconds(10); |
| 19505 | |
| 19506 | std::vector<MockWrite> data_writes = { |
| 19507 | MockWrite(ASYNC, 0, |
| 19508 | "GET / HTTP/1.1\r\n" |
| 19509 | "Host: www.example.org\r\n" |
| 19510 | "Connection: keep-alive\r\n"), |
| 19511 | MockWrite(ASYNC, 1, extra_header_string.data()), |
| 19512 | }; |
| 19513 | |
| 19514 | std::vector<MockRead> data_reads = { |
| 19515 | // Write one byte of the status line, followed by a pause. |
| 19516 | MockRead(ASYNC, 2, "H"), |
| 19517 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 19518 | MockRead(ASYNC, 4, "TTP/1.1 200 OK\r\n\r\n"), |
| 19519 | MockRead(ASYNC, 5, "hello world"), |
| 19520 | MockRead(SYNCHRONOUS, OK, 6), |
| 19521 | }; |
| 19522 | |
| 19523 | SequencedSocketData data(data_reads, data_writes); |
| 19524 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19525 | |
| 19526 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19527 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19528 | |
| 19529 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19530 | |
| 19531 | auto trans = |
| 19532 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19533 | |
| 19534 | TestCompletionCallback callback; |
| 19535 | |
| 19536 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19537 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19538 | |
| 19539 | data.RunUntilPaused(); |
| 19540 | ASSERT_TRUE(data.IsPaused()); |
| 19541 | FastForwardBy(kSleepDuration); |
| 19542 | data.Resume(); |
| 19543 | |
| 19544 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19545 | |
| 19546 | std::string response_data; |
| 19547 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19548 | EXPECT_EQ("hello world", response_data); |
| 19549 | |
| 19550 | trans.reset(); |
| 19551 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19552 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19553 | |
| 19554 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19555 | |
| 19556 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19557 | network_error_logging_service()->errors()[0]; |
| 19558 | |
| 19559 | // Sanity-check elapsed time in error report |
| 19560 | EXPECT_EQ(kSleepDuration, error.elapsed_time); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19561 | } |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19562 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19563 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 19564 | |
Batalov Vladislav | a4e97a50 | 2019-04-11 15:35:23 | [diff] [blame] | 19565 | TEST_F(HttpNetworkTransactionTest, AlwaysFailRequestToCache) { |
| 19566 | HttpRequestInfo request; |
| 19567 | request.method = "GET"; |
| 19568 | request.url = GURL("http://example.org/"); |
| 19569 | |
| 19570 | request.load_flags = LOAD_ONLY_FROM_CACHE; |
| 19571 | |
| 19572 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19573 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 19574 | TestCompletionCallback callback1; |
| 19575 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 19576 | |
| 19577 | EXPECT_THAT(rv, IsError(ERR_CACHE_MISS)); |
| 19578 | } |
| 19579 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 19580 | TEST_F(HttpNetworkTransactionTest, ZeroRTTDoesntConfirm) { |
| 19581 | HttpRequestInfo request; |
| 19582 | request.method = "GET"; |
| 19583 | request.url = GURL("https://www.example.org/"); |
| 19584 | request.traffic_annotation = |
| 19585 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19586 | |
| 19587 | MockWrite data_writes[] = { |
| 19588 | MockWrite("GET / HTTP/1.1\r\n" |
| 19589 | "Host: www.example.org\r\n" |
| 19590 | "Connection: keep-alive\r\n\r\n"), |
| 19591 | }; |
| 19592 | |
| 19593 | // The proxy responds to the connect with a 407, using a persistent |
| 19594 | // connection. |
| 19595 | MockRead data_reads[] = { |
| 19596 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19597 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19598 | MockRead(SYNCHRONOUS, "1"), |
| 19599 | }; |
| 19600 | |
| 19601 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19602 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19603 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19604 | ssl.confirm = MockConfirm(SYNCHRONOUS, OK); |
| 19605 | session_deps_.enable_early_data = true; |
| 19606 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19607 | |
| 19608 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19609 | |
| 19610 | TestCompletionCallback callback; |
| 19611 | auto trans = |
| 19612 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19613 | |
| 19614 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19615 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19616 | |
| 19617 | rv = callback.WaitForResult(); |
| 19618 | EXPECT_THAT(rv, IsOk()); |
| 19619 | |
| 19620 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19621 | ASSERT_TRUE(response); |
| 19622 | ASSERT_TRUE(response->headers); |
| 19623 | EXPECT_EQ(200, response->headers->response_code()); |
| 19624 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 19625 | |
| 19626 | // Check that ConfirmHandshake wasn't called. |
| 19627 | ASSERT_FALSE(ssl.ConfirmDataConsumed()); |
| 19628 | ASSERT_TRUE(ssl.WriteBeforeConfirm()); |
| 19629 | |
| 19630 | trans.reset(); |
| 19631 | |
| 19632 | session->CloseAllConnections(); |
| 19633 | } |
| 19634 | |
| 19635 | TEST_F(HttpNetworkTransactionTest, ZeroRTTSyncConfirmSyncWrite) { |
| 19636 | HttpRequestInfo request; |
| 19637 | request.method = "POST"; |
| 19638 | request.url = GURL("https://www.example.org/"); |
| 19639 | request.traffic_annotation = |
| 19640 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19641 | |
| 19642 | MockWrite data_writes[] = { |
| 19643 | MockWrite(SYNCHRONOUS, |
| 19644 | "POST / HTTP/1.1\r\n" |
| 19645 | "Host: www.example.org\r\n" |
| 19646 | "Connection: keep-alive\r\n" |
| 19647 | "Content-Length: 0\r\n\r\n"), |
| 19648 | }; |
| 19649 | |
| 19650 | // The proxy responds to the connect with a 407, using a persistent |
| 19651 | // connection. |
| 19652 | MockRead data_reads[] = { |
| 19653 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19654 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19655 | MockRead(SYNCHRONOUS, "1"), |
| 19656 | }; |
| 19657 | |
| 19658 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19659 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19660 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19661 | ssl.confirm = MockConfirm(SYNCHRONOUS, OK); |
| 19662 | session_deps_.enable_early_data = true; |
| 19663 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19664 | |
| 19665 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19666 | |
| 19667 | TestCompletionCallback callback; |
| 19668 | auto trans = |
| 19669 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19670 | |
| 19671 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19672 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19673 | |
| 19674 | rv = callback.WaitForResult(); |
| 19675 | EXPECT_THAT(rv, IsOk()); |
| 19676 | |
| 19677 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19678 | ASSERT_TRUE(response); |
| 19679 | ASSERT_TRUE(response->headers); |
| 19680 | EXPECT_EQ(200, response->headers->response_code()); |
| 19681 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 19682 | |
| 19683 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 19684 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 19685 | |
| 19686 | trans.reset(); |
| 19687 | |
| 19688 | session->CloseAllConnections(); |
| 19689 | } |
| 19690 | |
| 19691 | TEST_F(HttpNetworkTransactionTest, ZeroRTTSyncConfirmAsyncWrite) { |
| 19692 | HttpRequestInfo request; |
| 19693 | request.method = "POST"; |
| 19694 | request.url = GURL("https://www.example.org/"); |
| 19695 | request.traffic_annotation = |
| 19696 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19697 | |
| 19698 | MockWrite data_writes[] = { |
| 19699 | MockWrite(ASYNC, |
| 19700 | "POST / HTTP/1.1\r\n" |
| 19701 | "Host: www.example.org\r\n" |
| 19702 | "Connection: keep-alive\r\n" |
| 19703 | "Content-Length: 0\r\n\r\n"), |
| 19704 | }; |
| 19705 | |
| 19706 | // The proxy responds to the connect with a 407, using a persistent |
| 19707 | // connection. |
| 19708 | MockRead data_reads[] = { |
| 19709 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19710 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19711 | MockRead(SYNCHRONOUS, "1"), |
| 19712 | }; |
| 19713 | |
| 19714 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19715 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19716 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19717 | ssl.confirm = MockConfirm(SYNCHRONOUS, OK); |
| 19718 | session_deps_.enable_early_data = true; |
| 19719 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19720 | |
| 19721 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19722 | |
| 19723 | TestCompletionCallback callback; |
| 19724 | auto trans = |
| 19725 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19726 | |
| 19727 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19728 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19729 | |
| 19730 | rv = callback.WaitForResult(); |
| 19731 | EXPECT_THAT(rv, IsOk()); |
| 19732 | |
| 19733 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19734 | ASSERT_TRUE(response); |
| 19735 | ASSERT_TRUE(response->headers); |
| 19736 | EXPECT_EQ(200, response->headers->response_code()); |
| 19737 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 19738 | |
| 19739 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 19740 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 19741 | |
| 19742 | trans.reset(); |
| 19743 | |
| 19744 | session->CloseAllConnections(); |
| 19745 | } |
| 19746 | |
| 19747 | TEST_F(HttpNetworkTransactionTest, ZeroRTTAsyncConfirmSyncWrite) { |
| 19748 | HttpRequestInfo request; |
| 19749 | request.method = "POST"; |
| 19750 | request.url = GURL("https://www.example.org/"); |
| 19751 | request.traffic_annotation = |
| 19752 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19753 | |
| 19754 | MockWrite data_writes[] = { |
| 19755 | MockWrite(SYNCHRONOUS, |
| 19756 | "POST / HTTP/1.1\r\n" |
| 19757 | "Host: www.example.org\r\n" |
| 19758 | "Connection: keep-alive\r\n" |
| 19759 | "Content-Length: 0\r\n\r\n"), |
| 19760 | }; |
| 19761 | |
| 19762 | // The proxy responds to the connect with a 407, using a persistent |
| 19763 | // connection. |
| 19764 | MockRead data_reads[] = { |
| 19765 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19766 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19767 | MockRead(SYNCHRONOUS, "1"), |
| 19768 | }; |
| 19769 | |
| 19770 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19771 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19772 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19773 | ssl.confirm = MockConfirm(ASYNC, OK); |
| 19774 | session_deps_.enable_early_data = true; |
| 19775 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19776 | |
| 19777 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19778 | |
| 19779 | TestCompletionCallback callback; |
| 19780 | auto trans = |
| 19781 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19782 | |
| 19783 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19784 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19785 | |
| 19786 | rv = callback.WaitForResult(); |
| 19787 | EXPECT_THAT(rv, IsOk()); |
| 19788 | |
| 19789 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19790 | ASSERT_TRUE(response); |
| 19791 | ASSERT_TRUE(response->headers); |
| 19792 | EXPECT_EQ(200, response->headers->response_code()); |
| 19793 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 19794 | |
| 19795 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 19796 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 19797 | |
| 19798 | trans.reset(); |
| 19799 | |
| 19800 | session->CloseAllConnections(); |
| 19801 | } |
| 19802 | |
| 19803 | TEST_F(HttpNetworkTransactionTest, ZeroRTTAsyncConfirmAsyncWrite) { |
| 19804 | HttpRequestInfo request; |
| 19805 | request.method = "POST"; |
| 19806 | request.url = GURL("https://www.example.org/"); |
| 19807 | request.traffic_annotation = |
| 19808 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19809 | |
| 19810 | MockWrite data_writes[] = { |
| 19811 | MockWrite(ASYNC, |
| 19812 | "POST / HTTP/1.1\r\n" |
| 19813 | "Host: www.example.org\r\n" |
| 19814 | "Connection: keep-alive\r\n" |
| 19815 | "Content-Length: 0\r\n\r\n"), |
| 19816 | }; |
| 19817 | |
| 19818 | // The proxy responds to the connect with a 407, using a persistent |
| 19819 | // connection. |
| 19820 | MockRead data_reads[] = { |
| 19821 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19822 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19823 | MockRead(SYNCHRONOUS, "1"), |
| 19824 | }; |
| 19825 | |
| 19826 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19827 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19828 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19829 | ssl.confirm = MockConfirm(ASYNC, OK); |
| 19830 | session_deps_.enable_early_data = true; |
| 19831 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19832 | |
| 19833 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19834 | |
| 19835 | TestCompletionCallback callback; |
| 19836 | auto trans = |
| 19837 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19838 | |
| 19839 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19840 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19841 | |
| 19842 | rv = callback.WaitForResult(); |
| 19843 | EXPECT_THAT(rv, IsOk()); |
| 19844 | |
| 19845 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19846 | ASSERT_TRUE(response); |
| 19847 | ASSERT_TRUE(response->headers); |
| 19848 | EXPECT_EQ(200, response->headers->response_code()); |
| 19849 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 19850 | |
| 19851 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 19852 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 19853 | |
| 19854 | trans.reset(); |
| 19855 | |
| 19856 | session->CloseAllConnections(); |
| 19857 | } |
| 19858 | |
| 19859 | TEST_F(HttpNetworkTransactionTest, ZeroRTTConfirmErrorSync) { |
| 19860 | HttpRequestInfo request; |
| 19861 | request.method = "POST"; |
| 19862 | request.url = GURL("https://www.example.org/"); |
| 19863 | request.traffic_annotation = |
| 19864 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19865 | |
| 19866 | MockWrite data_writes[] = { |
| 19867 | MockWrite("POST / HTTP/1.1\r\n" |
| 19868 | "Host: www.example.org\r\n" |
| 19869 | "Connection: keep-alive\r\n" |
| 19870 | "Content-Length: 0\r\n\r\n"), |
| 19871 | }; |
| 19872 | |
| 19873 | // The proxy responds to the connect with a 407, using a persistent |
| 19874 | // connection. |
| 19875 | MockRead data_reads[] = { |
| 19876 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19877 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19878 | MockRead(SYNCHRONOUS, "1"), |
| 19879 | }; |
| 19880 | |
| 19881 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19882 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19883 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19884 | ssl.confirm = MockConfirm(SYNCHRONOUS, ERR_SSL_PROTOCOL_ERROR); |
| 19885 | session_deps_.enable_early_data = true; |
| 19886 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19887 | |
| 19888 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19889 | |
| 19890 | TestCompletionCallback callback; |
| 19891 | auto trans = |
| 19892 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19893 | |
| 19894 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19895 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19896 | |
| 19897 | rv = callback.WaitForResult(); |
| 19898 | EXPECT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
| 19899 | |
| 19900 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 19901 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 19902 | |
| 19903 | trans.reset(); |
| 19904 | |
| 19905 | session->CloseAllConnections(); |
| 19906 | } |
| 19907 | |
| 19908 | TEST_F(HttpNetworkTransactionTest, ZeroRTTConfirmErrorAsync) { |
| 19909 | HttpRequestInfo request; |
| 19910 | request.method = "POST"; |
| 19911 | request.url = GURL("https://www.example.org/"); |
| 19912 | request.traffic_annotation = |
| 19913 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19914 | |
| 19915 | MockWrite data_writes[] = { |
| 19916 | MockWrite("POST / HTTP/1.1\r\n" |
| 19917 | "Host: www.example.org\r\n" |
| 19918 | "Connection: keep-alive\r\n" |
| 19919 | "Content-Length: 0\r\n\r\n"), |
| 19920 | }; |
| 19921 | |
| 19922 | // The proxy responds to the connect with a 407, using a persistent |
| 19923 | // connection. |
| 19924 | MockRead data_reads[] = { |
| 19925 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19926 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19927 | MockRead(SYNCHRONOUS, "1"), |
| 19928 | }; |
| 19929 | |
| 19930 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19931 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19932 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19933 | ssl.confirm = MockConfirm(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
| 19934 | session_deps_.enable_early_data = true; |
| 19935 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19936 | |
| 19937 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19938 | |
| 19939 | TestCompletionCallback callback; |
| 19940 | auto trans = |
| 19941 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19942 | |
| 19943 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19944 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19945 | |
| 19946 | rv = callback.WaitForResult(); |
| 19947 | EXPECT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
| 19948 | |
| 19949 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 19950 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 19951 | |
| 19952 | trans.reset(); |
| 19953 | |
| 19954 | session->CloseAllConnections(); |
| 19955 | } |
| 19956 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 19957 | } // namespace net |