[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 | b5e433e | 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, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 696 | int id) override {} |
| 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. |
| 719 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 720 | if (!auth_challenge) |
| 721 | return false; |
| 722 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 723 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 724 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 725 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 726 | return true; |
| 727 | } |
| 728 | |
| 729 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 730 | if (!auth_challenge) |
| 731 | return false; |
| 732 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 733 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 734 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 735 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 736 | return true; |
| 737 | } |
| 738 | |
| 739 | bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 740 | if (!auth_challenge) |
| 741 | return false; |
| 742 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 743 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 744 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 745 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 746 | return true; |
| 747 | } |
| 748 | |
| 749 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 750 | if (!auth_challenge) |
| 751 | return false; |
| 752 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 753 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 754 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 755 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 756 | return true; |
| 757 | } |
| 758 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 759 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 760 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 761 | if (!auth_challenge) |
| 762 | return false; |
| 763 | EXPECT_FALSE(auth_challenge->is_proxy); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 764 | EXPECT_EQ("https://server", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 765 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 766 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 767 | return true; |
| 768 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 769 | |
| 770 | bool CheckNTLMProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 771 | if (!auth_challenge) |
| 772 | return false; |
| 773 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 774 | EXPECT_EQ("http://server", auth_challenge->challenger.Serialize()); |
| 775 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 776 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
| 777 | return true; |
| 778 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 779 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 780 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 781 | } // namespace |
| 782 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 783 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 784 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 785 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 786 | } |
| 787 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 788 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 789 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 790 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 791 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 792 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 793 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 794 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 795 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 796 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 797 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 798 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 799 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 800 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 801 | |
| 802 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 806 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 807 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 808 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 809 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 810 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 811 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 812 | EXPECT_THAT(out.rv, IsOk()); |
| 813 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 814 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 815 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 816 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 817 | } |
| 818 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 819 | // Response with no status line, and a weird port. Should fail by default. |
| 820 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 821 | MockRead data_reads[] = { |
| 822 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 823 | }; |
| 824 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 825 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 826 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 827 | |
| 828 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 829 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 830 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 831 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 832 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 833 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 834 | request.method = "GET"; |
| 835 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 836 | request.traffic_annotation = |
| 837 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 838 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 839 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 840 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 841 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 842 | } |
| 843 | |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 844 | // Tests that request info can be destroyed after the headers phase is complete. |
| 845 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoReadDestroyRequestInfo) { |
| 846 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 847 | auto trans = |
| 848 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 849 | |
| 850 | MockRead data_reads[] = { |
| 851 | MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Connection: keep-alive\r\n"), |
| 852 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, 0), |
| 853 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 854 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 855 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 856 | |
| 857 | TestCompletionCallback callback; |
| 858 | |
| 859 | { |
| 860 | auto request = std::make_unique<HttpRequestInfo>(); |
| 861 | request->method = "GET"; |
| 862 | request->url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 863 | request->traffic_annotation = |
| 864 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 865 | |
| 866 | int rv = |
| 867 | trans->Start(request.get(), callback.callback(), NetLogWithSource()); |
| 868 | |
| 869 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 870 | } // Let request info be destroyed. |
| 871 | |
| 872 | trans.reset(); |
| 873 | } |
| 874 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 875 | // Response with no status line, and a weird port. Option to allow weird ports |
| 876 | // enabled. |
| 877 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 878 | MockRead data_reads[] = { |
| 879 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 880 | }; |
| 881 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 882 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 883 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 884 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 885 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 886 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 887 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 888 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 889 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 890 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 891 | request.method = "GET"; |
| 892 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 893 | request.traffic_annotation = |
| 894 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 895 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 896 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 897 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 898 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 899 | |
| 900 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 901 | ASSERT_TRUE(info->headers); |
| 902 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 903 | |
| 904 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 905 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 906 | } |
| 907 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 908 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 909 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 910 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 911 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 912 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 913 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 914 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 915 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 916 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 917 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 918 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 919 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 923 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 924 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 925 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 926 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 927 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 928 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 929 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 930 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 931 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 932 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 933 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 937 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 938 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 939 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 940 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 941 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 942 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 943 | EXPECT_THAT(out.rv, IsOk()); |
| 944 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 945 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 946 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 947 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 951 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 952 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 953 | MockRead("\n"), |
| 954 | MockRead("\n"), |
| 955 | MockRead("Q"), |
| 956 | MockRead("J"), |
| 957 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 958 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 959 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 960 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 961 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 962 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 963 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 964 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 965 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 969 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 970 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 971 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 972 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 973 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 974 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 975 | EXPECT_THAT(out.rv, IsOk()); |
| 976 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 977 | EXPECT_EQ("HTT", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 978 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 979 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 980 | } |
| 981 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 982 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 983 | // persistent connection. The response should still terminate since a 204 |
| 984 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 985 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 986 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 987 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 988 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 989 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 990 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 991 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 992 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 993 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 994 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 995 | EXPECT_EQ("", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 996 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 997 | int64_t response_size = reads_size - strlen(junk); |
| 998 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 999 | } |
| 1000 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1001 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1002 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1003 | std::string final_chunk = "0\r\n\r\n"; |
| 1004 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 1005 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1006 | MockRead data_reads[] = { |
| 1007 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 1008 | MockRead("5\r\nHello\r\n"), |
| 1009 | MockRead("1\r\n"), |
| 1010 | MockRead(" \r\n"), |
| 1011 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1012 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1013 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1014 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1015 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1016 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1017 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1018 | EXPECT_EQ("Hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1019 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1020 | int64_t response_size = reads_size - extra_data.size(); |
| 1021 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1022 | } |
| 1023 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1024 | // Next tests deal with http://crbug.com/56344. |
| 1025 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1026 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1027 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 1028 | MockRead data_reads[] = { |
| 1029 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1030 | MockRead("Content-Length: 10\r\n"), |
| 1031 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1032 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1033 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1034 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1035 | } |
| 1036 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1037 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1038 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 1039 | MockRead data_reads[] = { |
| 1040 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1041 | MockRead("Content-Length: 5\r\n"), |
| 1042 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1043 | MockRead("Hello"), |
| 1044 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1045 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1046 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1047 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1048 | EXPECT_EQ("Hello", out.response_data); |
| 1049 | } |
| 1050 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1051 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1052 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1053 | // More than 2 dupes. |
| 1054 | { |
| 1055 | MockRead data_reads[] = { |
| 1056 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1057 | MockRead("Content-Length: 5\r\n"), |
| 1058 | MockRead("Content-Length: 5\r\n"), |
| 1059 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1060 | MockRead("Hello"), |
| 1061 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1062 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1063 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1064 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1065 | EXPECT_EQ("Hello", out.response_data); |
| 1066 | } |
| 1067 | // HTTP/1.0 |
| 1068 | { |
| 1069 | MockRead data_reads[] = { |
| 1070 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1071 | MockRead("Content-Length: 5\r\n"), |
| 1072 | MockRead("Content-Length: 5\r\n"), |
| 1073 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1074 | MockRead("Hello"), |
| 1075 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1076 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1077 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1078 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1079 | EXPECT_EQ("Hello", out.response_data); |
| 1080 | } |
| 1081 | // 2 dupes and one mismatched. |
| 1082 | { |
| 1083 | MockRead data_reads[] = { |
| 1084 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1085 | MockRead("Content-Length: 10\r\n"), |
| 1086 | MockRead("Content-Length: 10\r\n"), |
| 1087 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1088 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1089 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1090 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1091 | } |
| 1092 | } |
| 1093 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1094 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1095 | MultipleContentLengthHeadersTransferEncoding) { |
| 1096 | MockRead data_reads[] = { |
| 1097 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1098 | MockRead("Content-Length: 666\r\n"), |
| 1099 | MockRead("Content-Length: 1337\r\n"), |
| 1100 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1101 | MockRead("5\r\nHello\r\n"), |
| 1102 | MockRead("1\r\n"), |
| 1103 | MockRead(" \r\n"), |
| 1104 | MockRead("5\r\nworld\r\n"), |
| 1105 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1106 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1107 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1108 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1109 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1110 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1111 | EXPECT_EQ("Hello world", out.response_data); |
| 1112 | } |
| 1113 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1114 | // Next tests deal with http://crbug.com/98895. |
| 1115 | |
| 1116 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1117 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1118 | MockRead data_reads[] = { |
| 1119 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1120 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1121 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1122 | MockRead("Hello"), |
| 1123 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1124 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1125 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1126 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1127 | EXPECT_EQ("Hello", out.response_data); |
| 1128 | } |
| 1129 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1130 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1131 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1132 | MockRead data_reads[] = { |
| 1133 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1134 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1135 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1136 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1137 | MockRead("Hello"), |
| 1138 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1139 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1140 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1141 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1142 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1146 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1147 | MockRead data_reads[] = { |
| 1148 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1149 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1150 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1151 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1152 | MockRead("Hello"), |
| 1153 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1154 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1155 | EXPECT_THAT(out.rv, |
| 1156 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1157 | } |
| 1158 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1159 | // Checks that two identical Location headers result in no error. |
| 1160 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1161 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1162 | MockRead data_reads[] = { |
| 1163 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1164 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1165 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1166 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1167 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1168 | }; |
| 1169 | |
| 1170 | HttpRequestInfo request; |
| 1171 | request.method = "GET"; |
| 1172 | request.url = GURL("http://redirect.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1173 | request.traffic_annotation = |
| 1174 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1175 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1176 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1177 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1178 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1179 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1180 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1181 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1182 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1183 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1184 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1185 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1186 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1187 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1188 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1189 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1190 | ASSERT_TRUE(response); |
| 1191 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1192 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1193 | std::string url; |
| 1194 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1195 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1196 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1197 | } |
| 1198 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1199 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1200 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1201 | MockRead data_reads[] = { |
| 1202 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1203 | MockRead("Location: http://good.com/\r\n"), |
| 1204 | MockRead("Location: http://evil.com/\r\n"), |
| 1205 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1206 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1207 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1208 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1209 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1210 | } |
| 1211 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1212 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1213 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1214 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1215 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1216 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1217 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1218 | request.traffic_annotation = |
| 1219 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1220 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1221 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1222 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1223 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1224 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1225 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1226 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1227 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1228 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1229 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1230 | "Host: www.example.org\r\n" |
| 1231 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1232 | }; |
| 1233 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1234 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1235 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1236 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1237 | // No response body because the test stops reading here. |
| 1238 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1239 | }; |
| 1240 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1241 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1242 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1243 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1244 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1245 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1246 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1247 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1248 | |
| 1249 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1250 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1251 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1252 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1253 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1254 | |
| 1255 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1256 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1257 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1258 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1259 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1260 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1261 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1262 | |
| 1263 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1264 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1265 | bool has_server_header = response->headers->EnumerateHeader( |
| 1266 | &iter, "Server", &server_header); |
| 1267 | EXPECT_TRUE(has_server_header); |
| 1268 | EXPECT_EQ("Blah", server_header); |
| 1269 | |
| 1270 | // Reading should give EOF right away, since there is no message body |
| 1271 | // (despite non-zero content-length). |
| 1272 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1273 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1274 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1275 | EXPECT_EQ("", response_data); |
| 1276 | } |
| 1277 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1278 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1279 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1280 | |
| 1281 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1282 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1283 | MockRead("hello"), |
| 1284 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1285 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1286 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1287 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1288 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1289 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1290 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1291 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1292 | "hello", "world" |
| 1293 | }; |
| 1294 | |
| 1295 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1296 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1297 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1298 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1299 | request.traffic_annotation = |
| 1300 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1301 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1302 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1303 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1304 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1305 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1306 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1307 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1308 | |
| 1309 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1310 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1311 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1312 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1313 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1314 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1315 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1316 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1317 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1318 | |
| 1319 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1320 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1321 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1322 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1323 | } |
| 1324 | } |
| 1325 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1326 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1327 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1328 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1329 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1330 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1331 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1332 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1333 | request.method = "POST"; |
| 1334 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1335 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1336 | request.traffic_annotation = |
| 1337 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1338 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1339 | // Check the upload progress returned before initialization is correct. |
| 1340 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1341 | EXPECT_EQ(0u, progress.size()); |
| 1342 | EXPECT_EQ(0u, progress.position()); |
| 1343 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1344 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1345 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1346 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1347 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1348 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1349 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1350 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1351 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1352 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1353 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1354 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1355 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1356 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1357 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1358 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1359 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1360 | |
| 1361 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1362 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1363 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1364 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1365 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1366 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1367 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1368 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1369 | |
| 1370 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1371 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1372 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1373 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1374 | } |
| 1375 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1376 | // This test is almost the same as Ignores100 above, but the response contains |
| 1377 | // 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] | 1378 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1379 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1380 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1381 | request.method = "GET"; |
| 1382 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1383 | request.traffic_annotation = |
| 1384 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1385 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1386 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1387 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1388 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1389 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1390 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1391 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1392 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1393 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1394 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1395 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1396 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1397 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1398 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1399 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1400 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1401 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1402 | |
| 1403 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1404 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1405 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1406 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1407 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1408 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1409 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1410 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1411 | |
| 1412 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1413 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1414 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1415 | EXPECT_EQ("hello world", response_data); |
| 1416 | } |
| 1417 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1418 | TEST_F(HttpNetworkTransactionTest, LoadTimingMeasuresTimeToFirstByteForHttp) { |
| 1419 | static const base::TimeDelta kDelayAfterFirstByte = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1420 | base::TimeDelta::FromMilliseconds(10); |
| 1421 | |
| 1422 | HttpRequestInfo request; |
| 1423 | request.method = "GET"; |
| 1424 | request.url = GURL("http://www.foo.com/"); |
| 1425 | request.traffic_annotation = |
| 1426 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1427 | |
| 1428 | std::vector<MockWrite> data_writes = { |
| 1429 | MockWrite(ASYNC, 0, |
| 1430 | "GET / HTTP/1.1\r\n" |
| 1431 | "Host: www.foo.com\r\n" |
| 1432 | "Connection: keep-alive\r\n\r\n"), |
| 1433 | }; |
| 1434 | |
| 1435 | std::vector<MockRead> data_reads = { |
| 1436 | // Write one byte of the status line, followed by a pause. |
| 1437 | MockRead(ASYNC, 1, "H"), |
| 1438 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1439 | MockRead(ASYNC, 3, "TTP/1.1 200 OK\r\n\r\n"), |
| 1440 | MockRead(ASYNC, 4, "hello world"), |
| 1441 | MockRead(SYNCHRONOUS, OK, 5), |
| 1442 | }; |
| 1443 | |
| 1444 | SequencedSocketData data(data_reads, data_writes); |
| 1445 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1446 | |
| 1447 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1448 | |
| 1449 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1450 | |
| 1451 | TestCompletionCallback callback; |
| 1452 | |
| 1453 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1454 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1455 | |
| 1456 | data.RunUntilPaused(); |
| 1457 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1458 | FastForwardBy(kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1459 | data.Resume(); |
| 1460 | |
| 1461 | rv = callback.WaitForResult(); |
| 1462 | EXPECT_THAT(rv, IsOk()); |
| 1463 | |
| 1464 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1465 | ASSERT_TRUE(response); |
| 1466 | |
| 1467 | EXPECT_TRUE(response->headers); |
| 1468 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1469 | |
| 1470 | LoadTimingInfo load_timing_info; |
| 1471 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1472 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1473 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1474 | // Ensure we didn't include the delay in the TTFB time. |
| 1475 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1476 | load_timing_info.connect_timing.connect_end); |
| 1477 | // Ensure that the mock clock advanced at all. |
| 1478 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1479 | kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1480 | |
| 1481 | std::string response_data; |
| 1482 | rv = ReadTransaction(&trans, &response_data); |
| 1483 | EXPECT_THAT(rv, IsOk()); |
| 1484 | EXPECT_EQ("hello world", response_data); |
| 1485 | } |
| 1486 | |
| 1487 | // Tests that the time-to-first-byte reported in a transaction's load timing |
| 1488 | // info uses the first response, even if 1XX/informational. |
| 1489 | void HttpNetworkTransactionTest::Check100ResponseTiming(bool use_spdy) { |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1490 | static const base::TimeDelta kDelayAfter100Response = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1491 | base::TimeDelta::FromMilliseconds(10); |
| 1492 | |
| 1493 | HttpRequestInfo request; |
| 1494 | request.method = "GET"; |
| 1495 | request.url = GURL("https://www.foo.com/"); |
| 1496 | request.traffic_annotation = |
| 1497 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1498 | |
| 1499 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 1500 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 1501 | |
| 1502 | std::vector<MockWrite> data_writes; |
| 1503 | std::vector<MockRead> data_reads; |
| 1504 | |
| 1505 | spdy::SpdySerializedFrame spdy_req( |
| 1506 | spdy_util_.ConstructSpdyGet(request.url.spec().c_str(), 1, LOWEST)); |
| 1507 | |
| 1508 | spdy::SpdyHeaderBlock spdy_resp1_headers; |
| 1509 | spdy_resp1_headers[spdy::kHttp2StatusHeader] = "100"; |
| 1510 | spdy::SpdySerializedFrame spdy_resp1( |
| 1511 | spdy_util_.ConstructSpdyReply(1, spdy_resp1_headers.Clone())); |
| 1512 | spdy::SpdySerializedFrame spdy_resp2( |
| 1513 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 1514 | spdy::SpdySerializedFrame spdy_data( |
| 1515 | spdy_util_.ConstructSpdyDataFrame(1, "hello world", true)); |
| 1516 | |
| 1517 | if (use_spdy) { |
| 1518 | ssl.next_proto = kProtoHTTP2; |
| 1519 | |
| 1520 | data_writes = {CreateMockWrite(spdy_req, 0)}; |
| 1521 | |
| 1522 | data_reads = { |
| 1523 | CreateMockRead(spdy_resp1, 1), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1524 | CreateMockRead(spdy_resp2, 3), CreateMockRead(spdy_data, 4), |
| 1525 | MockRead(SYNCHRONOUS, OK, 5), |
| 1526 | }; |
| 1527 | } else { |
| 1528 | data_writes = { |
| 1529 | MockWrite(ASYNC, 0, |
| 1530 | "GET / HTTP/1.1\r\n" |
| 1531 | "Host: www.foo.com\r\n" |
| 1532 | "Connection: keep-alive\r\n\r\n"), |
| 1533 | }; |
| 1534 | |
| 1535 | data_reads = { |
| 1536 | MockRead(ASYNC, 1, "HTTP/1.1 100 Continue\r\n\r\n"), |
| 1537 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1538 | |
| 1539 | MockRead(ASYNC, 3, "HTTP/1.1 200 OK\r\n\r\n"), |
| 1540 | MockRead(ASYNC, 4, "hello world"), |
| 1541 | MockRead(SYNCHRONOUS, OK, 5), |
| 1542 | }; |
| 1543 | } |
| 1544 | |
| 1545 | SequencedSocketData data(data_reads, data_writes); |
| 1546 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1547 | |
| 1548 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1549 | |
| 1550 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1551 | |
| 1552 | TestCompletionCallback callback; |
| 1553 | |
| 1554 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1555 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1556 | |
| 1557 | data.RunUntilPaused(); |
| 1558 | // We should now have parsed the 100 response and hit ERR_IO_PENDING. Insert |
| 1559 | // the delay before parsing the 200 response. |
| 1560 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1561 | FastForwardBy(kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1562 | data.Resume(); |
| 1563 | |
| 1564 | rv = callback.WaitForResult(); |
| 1565 | EXPECT_THAT(rv, IsOk()); |
| 1566 | |
| 1567 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1568 | ASSERT_TRUE(response); |
| 1569 | |
| 1570 | LoadTimingInfo load_timing_info; |
| 1571 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1572 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1573 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1574 | // Ensure we didn't include the delay in the TTFB time. |
| 1575 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1576 | load_timing_info.connect_timing.connect_end); |
| 1577 | // Ensure that the mock clock advanced at all. |
| 1578 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1579 | kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1580 | |
| 1581 | std::string response_data; |
| 1582 | rv = ReadTransaction(&trans, &response_data); |
| 1583 | EXPECT_THAT(rv, IsOk()); |
| 1584 | EXPECT_EQ("hello world", response_data); |
| 1585 | } |
| 1586 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1587 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForHttp) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1588 | Check100ResponseTiming(false /* use_spdy */); |
| 1589 | } |
| 1590 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1591 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForSpdy) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1592 | Check100ResponseTiming(true /* use_spdy */); |
| 1593 | } |
| 1594 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1595 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1596 | HttpRequestInfo request; |
| 1597 | request.method = "POST"; |
| 1598 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1599 | request.traffic_annotation = |
| 1600 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1601 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1602 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1603 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1604 | |
| 1605 | MockRead data_reads[] = { |
| 1606 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1607 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1608 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1609 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1610 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1611 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1612 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1613 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1614 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1615 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1616 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1617 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1618 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1619 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1620 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1621 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1622 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1623 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1624 | } |
| 1625 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1626 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1627 | HttpRequestInfo request; |
| 1628 | request.method = "POST"; |
| 1629 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1630 | request.traffic_annotation = |
| 1631 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1632 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1633 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1634 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1635 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1636 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1637 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1638 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1639 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1640 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1641 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1642 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1643 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1644 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1645 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1646 | |
| 1647 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1648 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1649 | } |
| 1650 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1651 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1652 | const MockWrite* write_failure, |
| 1653 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1654 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1655 | request.method = "GET"; |
| 1656 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1657 | request.traffic_annotation = |
| 1658 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1659 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1660 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1661 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1662 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1663 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1664 | // Written data for successfully sending both requests. |
| 1665 | MockWrite data1_writes[] = { |
| 1666 | MockWrite("GET / HTTP/1.1\r\n" |
| 1667 | "Host: www.foo.com\r\n" |
| 1668 | "Connection: keep-alive\r\n\r\n"), |
| 1669 | MockWrite("GET / HTTP/1.1\r\n" |
| 1670 | "Host: www.foo.com\r\n" |
| 1671 | "Connection: keep-alive\r\n\r\n") |
| 1672 | }; |
| 1673 | |
| 1674 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1675 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1676 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1677 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1678 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1679 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1680 | |
| 1681 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1682 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1683 | data1_writes[1] = *write_failure; |
| 1684 | } else { |
| 1685 | ASSERT_TRUE(read_failure); |
| 1686 | data1_reads[2] = *read_failure; |
| 1687 | } |
| 1688 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1689 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1690 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1691 | |
| 1692 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1693 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1694 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1695 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1696 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1697 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1698 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1699 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1700 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1701 | "hello", "world" |
| 1702 | }; |
| 1703 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1704 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1705 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1706 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1707 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1708 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1709 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1710 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1711 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1712 | |
| 1713 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1714 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1715 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1716 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1717 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1718 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1719 | if (i == 0) { |
| 1720 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1721 | } else { |
| 1722 | // The second request should be using a new socket. |
| 1723 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1724 | } |
| 1725 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1726 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1727 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1728 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1729 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1730 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1731 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1732 | |
| 1733 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1734 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1735 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1736 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1737 | } |
| 1738 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1739 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1740 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1741 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1742 | const MockRead* read_failure, |
| 1743 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1744 | HttpRequestInfo request; |
| 1745 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1746 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1747 | request.traffic_annotation = |
| 1748 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1749 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1750 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1751 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1752 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1753 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1754 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1755 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1756 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1757 | ssl1.next_proto = kProtoHTTP2; |
| 1758 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1759 | } |
| 1760 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1761 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1762 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1763 | // SPDY versions of the request and response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1764 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1765 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1766 | spdy::SpdySerializedFrame spdy_response( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1767 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1768 | spdy::SpdySerializedFrame spdy_data( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 1769 | spdy_util_.ConstructSpdyDataFrame(1, "hello", true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1770 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1771 | // HTTP/1.1 versions of the request and response. |
| 1772 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1773 | "Host: www.foo.com\r\n" |
| 1774 | "Connection: keep-alive\r\n\r\n"; |
| 1775 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1776 | const char kHttpData[] = "hello"; |
| 1777 | |
| 1778 | std::vector<MockRead> data1_reads; |
| 1779 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1780 | if (write_failure) { |
| 1781 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1782 | data1_writes.push_back(*write_failure); |
| 1783 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1784 | } else { |
| 1785 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1786 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1787 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1788 | } else { |
| 1789 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1790 | } |
| 1791 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1792 | } |
| 1793 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1794 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1795 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1796 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1797 | std::vector<MockRead> data2_reads; |
| 1798 | std::vector<MockWrite> data2_writes; |
| 1799 | |
| 1800 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1801 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1802 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1803 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1804 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1805 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1806 | } else { |
| 1807 | data2_writes.push_back( |
| 1808 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1809 | |
| 1810 | data2_reads.push_back( |
| 1811 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1812 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1813 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1814 | } |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1815 | SequencedSocketData data2(data2_reads, data2_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1816 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1817 | |
| 1818 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1819 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1820 | // Wait for the preconnect to complete. |
| 1821 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1822 | base::RunLoop().RunUntilIdle(); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 1823 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1824 | |
| 1825 | // Make the request. |
| 1826 | TestCompletionCallback callback; |
| 1827 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1828 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1829 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1830 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1831 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1832 | |
| 1833 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1834 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1835 | |
| 1836 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1837 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1838 | TestLoadTimingNotReused( |
| 1839 | load_timing_info, |
| 1840 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1841 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1842 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1843 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1844 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1845 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1846 | if (response->was_fetched_via_spdy) { |
| 1847 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1848 | } else { |
| 1849 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1850 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1851 | |
| 1852 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1853 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1854 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1855 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1856 | } |
| 1857 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1858 | // Test that we do not retry indefinitely when a server sends an error like |
| 1859 | // ERR_SPDY_PING_FAILED, ERR_SPDY_SERVER_REFUSED_STREAM, |
| 1860 | // ERR_QUIC_HANDSHAKE_FAILED or ERR_QUIC_PROTOCOL_ERROR. |
| 1861 | TEST_F(HttpNetworkTransactionTest, FiniteRetriesOnIOError) { |
| 1862 | HttpRequestInfo request; |
| 1863 | request.method = "GET"; |
| 1864 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1865 | request.traffic_annotation = |
| 1866 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1867 | |
| 1868 | // Check whether we give up after the third try. |
| 1869 | |
| 1870 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1871 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1872 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1873 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1874 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1875 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1876 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1877 | |
| 1878 | // Three go away responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1879 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1880 | StaticSocketDataProvider data2(data_read1, data_write); |
| 1881 | StaticSocketDataProvider data3(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1882 | |
| 1883 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1884 | AddSSLSocketData(); |
| 1885 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1886 | AddSSLSocketData(); |
| 1887 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1888 | AddSSLSocketData(); |
| 1889 | |
| 1890 | TestCompletionCallback callback; |
| 1891 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1892 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1893 | |
| 1894 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1895 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1896 | |
| 1897 | rv = callback.WaitForResult(); |
| 1898 | EXPECT_THAT(rv, IsError(ERR_SPDY_SERVER_REFUSED_STREAM)); |
| 1899 | } |
| 1900 | |
| 1901 | TEST_F(HttpNetworkTransactionTest, RetryTwiceOnIOError) { |
| 1902 | HttpRequestInfo request; |
| 1903 | request.method = "GET"; |
| 1904 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1905 | request.traffic_annotation = |
| 1906 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1907 | |
| 1908 | // Check whether we try atleast thrice before giving up. |
| 1909 | |
| 1910 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1911 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1912 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1913 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1914 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1915 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1916 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1917 | |
| 1918 | // Construct a non error HTTP2 response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1919 | spdy::SpdySerializedFrame spdy_response_no_error( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1920 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1921 | spdy::SpdySerializedFrame spdy_data( |
| 1922 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1923 | MockRead data_read2[] = {CreateMockRead(spdy_response_no_error, 1), |
| 1924 | CreateMockRead(spdy_data, 2)}; |
| 1925 | |
| 1926 | // Two error responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1927 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1928 | StaticSocketDataProvider data2(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1929 | // Followed by a success response. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1930 | SequencedSocketData data3(data_read2, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1931 | |
| 1932 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1933 | AddSSLSocketData(); |
| 1934 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1935 | AddSSLSocketData(); |
| 1936 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1937 | AddSSLSocketData(); |
| 1938 | |
| 1939 | TestCompletionCallback callback; |
| 1940 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1941 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1942 | |
| 1943 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1944 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1945 | |
| 1946 | rv = callback.WaitForResult(); |
| 1947 | EXPECT_THAT(rv, IsOk()); |
| 1948 | } |
| 1949 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1950 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1951 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1952 | KeepAliveConnectionResendRequestTest(&write_failure, nullptr); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1953 | } |
| 1954 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1955 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1956 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1957 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1958 | } |
| 1959 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1960 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1961 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1962 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1963 | } |
| 1964 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1965 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1966 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1967 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1968 | MockRead read_failure(SYNCHRONOUS, |
| 1969 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1970 | "Connection: Keep-Alive\r\n" |
| 1971 | "Content-Length: 6\r\n\r\n" |
| 1972 | "Pickle"); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1973 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1974 | } |
| 1975 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1976 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1977 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1978 | PreconnectErrorResendRequestTest(&write_failure, nullptr, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1979 | } |
| 1980 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1981 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1982 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1983 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1984 | } |
| 1985 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1986 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1987 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1988 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1989 | } |
| 1990 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1991 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1992 | MockRead read_failure(ASYNC, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1993 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1994 | } |
| 1995 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1996 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1997 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1998 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1999 | MockRead read_failure(SYNCHRONOUS, |
| 2000 | "HTTP/1.1 408 Request Timeout\r\n" |
| 2001 | "Connection: Keep-Alive\r\n" |
| 2002 | "Content-Length: 6\r\n\r\n" |
| 2003 | "Pickle"); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2004 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
| 2005 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2006 | } |
| 2007 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2008 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2009 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2010 | PreconnectErrorResendRequestTest(&write_failure, nullptr, true); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2011 | } |
| 2012 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2013 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2014 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2015 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2016 | } |
| 2017 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2018 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2019 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2020 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2021 | } |
| 2022 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2023 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2024 | MockRead read_failure(ASYNC, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2025 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2026 | } |
| 2027 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2028 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2029 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2030 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2031 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2032 | request.traffic_annotation = |
| 2033 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2034 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2035 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2036 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2037 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2038 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2039 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2040 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2041 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2042 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2043 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2044 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2045 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2046 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2047 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2048 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2049 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2050 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2051 | |
| 2052 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2053 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2054 | |
| 2055 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2056 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2057 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2058 | } |
| 2059 | |
| 2060 | // What do various browsers do when the server closes a non-keepalive |
| 2061 | // connection without sending any response header or body? |
| 2062 | // |
| 2063 | // IE7: error page |
| 2064 | // Safari 3.1.2 (Windows): error page |
| 2065 | // Firefox 3.0.1: blank page |
| 2066 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2067 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 2068 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2069 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2070 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2071 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2072 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2073 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2074 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2075 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2076 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2077 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2078 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 2079 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2080 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 2081 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 2082 | // destructor in such situations. |
| 2083 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2084 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2085 | HttpRequestInfo request; |
| 2086 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2087 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2088 | request.traffic_annotation = |
| 2089 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2090 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2091 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2092 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2093 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2094 | |
| 2095 | MockRead data_reads[] = { |
| 2096 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2097 | MockRead("Connection: keep-alive\r\n"), |
| 2098 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2099 | MockRead("hello"), |
| 2100 | MockRead(SYNCHRONOUS, 0), |
| 2101 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2102 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2103 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2104 | |
| 2105 | TestCompletionCallback callback; |
| 2106 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2107 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2108 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2109 | |
| 2110 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2111 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2112 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2113 | scoped_refptr<IOBufferWithSize> io_buf = |
| 2114 | base::MakeRefCounted<IOBufferWithSize>(100); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2115 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2116 | if (rv == ERR_IO_PENDING) |
| 2117 | rv = callback.WaitForResult(); |
| 2118 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2119 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2120 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2121 | |
| 2122 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2123 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2124 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2125 | } |
| 2126 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2127 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2128 | HttpRequestInfo request; |
| 2129 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2130 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2131 | request.traffic_annotation = |
| 2132 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2133 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2134 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2135 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2136 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2137 | |
| 2138 | MockRead data_reads[] = { |
| 2139 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2140 | MockRead("Connection: keep-alive\r\n"), |
| 2141 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2142 | MockRead(SYNCHRONOUS, 0), |
| 2143 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2144 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2145 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2146 | |
| 2147 | TestCompletionCallback callback; |
| 2148 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2149 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2150 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2151 | |
| 2152 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2153 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2154 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2155 | scoped_refptr<IOBufferWithSize> io_buf( |
| 2156 | base::MakeRefCounted<IOBufferWithSize>(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2157 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2158 | if (rv == ERR_IO_PENDING) |
| 2159 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2160 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2161 | |
| 2162 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2163 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2164 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2165 | } |
| 2166 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2167 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 2168 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2169 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2170 | HttpRequestInfo request; |
| 2171 | request.method = "GET"; |
| 2172 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2173 | request.traffic_annotation = |
| 2174 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2175 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2176 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2177 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2178 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2179 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2180 | const char* request_data = |
| 2181 | "GET / HTTP/1.1\r\n" |
| 2182 | "Host: www.foo.com\r\n" |
| 2183 | "Connection: keep-alive\r\n\r\n"; |
| 2184 | MockWrite data_writes[] = { |
| 2185 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 2186 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 2187 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 2188 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 2189 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 2190 | }; |
| 2191 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2192 | // Note that because all these reads happen in the same |
| 2193 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 2194 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2195 | MockRead data_reads[] = { |
| 2196 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 2197 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 2198 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 2199 | MockRead(ASYNC, 7, |
| 2200 | "HTTP/1.1 302 Found\r\n" |
| 2201 | "Content-Length: 0\r\n\r\n"), |
| 2202 | MockRead(ASYNC, 9, |
| 2203 | "HTTP/1.1 302 Found\r\n" |
| 2204 | "Content-Length: 5\r\n\r\n" |
| 2205 | "hello"), |
| 2206 | MockRead(ASYNC, 11, |
| 2207 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2208 | "Content-Length: 0\r\n\r\n"), |
| 2209 | MockRead(ASYNC, 13, |
| 2210 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2211 | "Content-Length: 5\r\n\r\n" |
| 2212 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2213 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2214 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 2215 | // the set_busy_before_sync_reads(true) call, while the |
| 2216 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 2217 | // reuseable. See http://crbug.com/544255. |
| 2218 | MockRead(ASYNC, 15, |
| 2219 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2220 | "Content-Length: 5\r\n\r\n"), |
| 2221 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2222 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2223 | MockRead(ASYNC, 18, |
| 2224 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2225 | "Content-Length: 5\r\n\r\n" |
| 2226 | "he"), |
| 2227 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 2228 | |
| 2229 | // The body of the final request is actually read. |
| 2230 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 2231 | MockRead(ASYNC, 22, "hello"), |
| 2232 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2233 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2234 | data.set_busy_before_sync_reads(true); |
| 2235 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2236 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2237 | const int kNumUnreadBodies = base::size(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2238 | std::string response_lines[kNumUnreadBodies]; |
| 2239 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 2240 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2241 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2242 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2243 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2244 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2245 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2246 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2247 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2248 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2249 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2250 | LoadTimingInfo load_timing_info; |
| 2251 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2252 | if (i == 0) { |
| 2253 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2254 | first_socket_log_id = load_timing_info.socket_log_id; |
| 2255 | } else { |
| 2256 | TestLoadTimingReused(load_timing_info); |
| 2257 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 2258 | } |
| 2259 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2260 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2261 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2262 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2263 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2264 | response_lines[i] = response->headers->GetStatusLine(); |
| 2265 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2266 | // Delete the transaction without reading the response bodies. Then spin |
| 2267 | // the message loop, so the response bodies are drained. |
| 2268 | trans.reset(); |
| 2269 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2270 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2271 | |
| 2272 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2273 | "HTTP/1.1 204 No Content", |
| 2274 | "HTTP/1.1 205 Reset Content", |
| 2275 | "HTTP/1.1 304 Not Modified", |
| 2276 | "HTTP/1.1 302 Found", |
| 2277 | "HTTP/1.1 302 Found", |
| 2278 | "HTTP/1.1 301 Moved Permanently", |
| 2279 | "HTTP/1.1 301 Moved Permanently", |
| 2280 | "HTTP/1.1 200 Hunky-Dory", |
| 2281 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2282 | }; |
| 2283 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2284 | static_assert(kNumUnreadBodies == base::size(kStatusLines), |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2285 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2286 | |
| 2287 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2288 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2289 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2290 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2291 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2292 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2293 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2294 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2295 | ASSERT_TRUE(response); |
| 2296 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2297 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2298 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2299 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2300 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2301 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2302 | } |
| 2303 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2304 | // Sockets that receive extra data after a response is complete should not be |
| 2305 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2306 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2307 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2308 | MockWrite data_writes1[] = { |
| 2309 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2310 | "Host: www.borked.com\r\n" |
| 2311 | "Connection: keep-alive\r\n\r\n"), |
| 2312 | }; |
| 2313 | |
| 2314 | MockRead data_reads1[] = { |
| 2315 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2316 | "Connection: keep-alive\r\n" |
| 2317 | "Content-Length: 22\r\n\r\n" |
| 2318 | "This server is borked."), |
| 2319 | }; |
| 2320 | |
| 2321 | MockWrite data_writes2[] = { |
| 2322 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2323 | "Host: www.borked.com\r\n" |
| 2324 | "Connection: keep-alive\r\n\r\n"), |
| 2325 | }; |
| 2326 | |
| 2327 | MockRead data_reads2[] = { |
| 2328 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2329 | "Content-Length: 3\r\n\r\n" |
| 2330 | "foo"), |
| 2331 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2332 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2333 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2334 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2335 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2336 | |
| 2337 | TestCompletionCallback callback; |
| 2338 | HttpRequestInfo request1; |
| 2339 | request1.method = "HEAD"; |
| 2340 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2341 | request1.traffic_annotation = |
| 2342 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2343 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2344 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2345 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2346 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2347 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2348 | |
| 2349 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2350 | ASSERT_TRUE(response1); |
| 2351 | ASSERT_TRUE(response1->headers); |
| 2352 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2353 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2354 | |
| 2355 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2356 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2357 | EXPECT_EQ("", response_data1); |
| 2358 | // Deleting the transaction attempts to release the socket back into the |
| 2359 | // socket pool. |
| 2360 | trans1.reset(); |
| 2361 | |
| 2362 | HttpRequestInfo request2; |
| 2363 | request2.method = "GET"; |
| 2364 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2365 | request2.traffic_annotation = |
| 2366 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2367 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2368 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2369 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2370 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2371 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2372 | |
| 2373 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2374 | ASSERT_TRUE(response2); |
| 2375 | ASSERT_TRUE(response2->headers); |
| 2376 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2377 | |
| 2378 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2379 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2380 | EXPECT_EQ("foo", response_data2); |
| 2381 | } |
| 2382 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2383 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2384 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2385 | MockWrite data_writes1[] = { |
| 2386 | MockWrite("GET / HTTP/1.1\r\n" |
| 2387 | "Host: www.borked.com\r\n" |
| 2388 | "Connection: keep-alive\r\n\r\n"), |
| 2389 | }; |
| 2390 | |
| 2391 | MockRead data_reads1[] = { |
| 2392 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2393 | "Connection: keep-alive\r\n" |
| 2394 | "Content-Length: 22\r\n\r\n" |
| 2395 | "This server is borked." |
| 2396 | "Bonus data!"), |
| 2397 | }; |
| 2398 | |
| 2399 | MockWrite data_writes2[] = { |
| 2400 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2401 | "Host: www.borked.com\r\n" |
| 2402 | "Connection: keep-alive\r\n\r\n"), |
| 2403 | }; |
| 2404 | |
| 2405 | MockRead data_reads2[] = { |
| 2406 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2407 | "Content-Length: 3\r\n\r\n" |
| 2408 | "foo"), |
| 2409 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2410 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2411 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2412 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2413 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2414 | |
| 2415 | TestCompletionCallback callback; |
| 2416 | HttpRequestInfo request1; |
| 2417 | request1.method = "GET"; |
| 2418 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2419 | request1.traffic_annotation = |
| 2420 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2421 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2422 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2423 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2424 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2425 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2426 | |
| 2427 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2428 | ASSERT_TRUE(response1); |
| 2429 | ASSERT_TRUE(response1->headers); |
| 2430 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2431 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2432 | |
| 2433 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2434 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2435 | EXPECT_EQ("This server is borked.", response_data1); |
| 2436 | // Deleting the transaction attempts to release the socket back into the |
| 2437 | // socket pool. |
| 2438 | trans1.reset(); |
| 2439 | |
| 2440 | HttpRequestInfo request2; |
| 2441 | request2.method = "GET"; |
| 2442 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2443 | request2.traffic_annotation = |
| 2444 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2445 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2446 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2447 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2448 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2449 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2450 | |
| 2451 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2452 | ASSERT_TRUE(response2); |
| 2453 | ASSERT_TRUE(response2->headers); |
| 2454 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2455 | |
| 2456 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2457 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2458 | EXPECT_EQ("foo", response_data2); |
| 2459 | } |
| 2460 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2461 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2462 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2463 | MockWrite data_writes1[] = { |
| 2464 | MockWrite("GET / HTTP/1.1\r\n" |
| 2465 | "Host: www.borked.com\r\n" |
| 2466 | "Connection: keep-alive\r\n\r\n"), |
| 2467 | }; |
| 2468 | |
| 2469 | MockRead data_reads1[] = { |
| 2470 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2471 | "Connection: keep-alive\r\n" |
| 2472 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2473 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2474 | MockRead("0\r\n\r\nBonus data!"), |
| 2475 | }; |
| 2476 | |
| 2477 | MockWrite data_writes2[] = { |
| 2478 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2479 | "Host: www.borked.com\r\n" |
| 2480 | "Connection: keep-alive\r\n\r\n"), |
| 2481 | }; |
| 2482 | |
| 2483 | MockRead data_reads2[] = { |
| 2484 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2485 | "Content-Length: 3\r\n\r\n" |
| 2486 | "foo"), |
| 2487 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2488 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2489 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2490 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2491 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2492 | |
| 2493 | TestCompletionCallback callback; |
| 2494 | HttpRequestInfo request1; |
| 2495 | request1.method = "GET"; |
| 2496 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2497 | request1.traffic_annotation = |
| 2498 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2499 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2500 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2501 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2502 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2503 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2504 | |
| 2505 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2506 | ASSERT_TRUE(response1); |
| 2507 | ASSERT_TRUE(response1->headers); |
| 2508 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2509 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2510 | |
| 2511 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2512 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2513 | EXPECT_EQ("This server is borked.", response_data1); |
| 2514 | // Deleting the transaction attempts to release the socket back into the |
| 2515 | // socket pool. |
| 2516 | trans1.reset(); |
| 2517 | |
| 2518 | HttpRequestInfo request2; |
| 2519 | request2.method = "GET"; |
| 2520 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2521 | request2.traffic_annotation = |
| 2522 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2523 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2524 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2525 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2526 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2527 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2528 | |
| 2529 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2530 | ASSERT_TRUE(response2); |
| 2531 | ASSERT_TRUE(response2->headers); |
| 2532 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2533 | |
| 2534 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2535 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2536 | EXPECT_EQ("foo", response_data2); |
| 2537 | } |
| 2538 | |
| 2539 | // This is a little different from the others - it tests the case that the |
| 2540 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2541 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2542 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2543 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2544 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2545 | MockWrite data_writes1[] = { |
| 2546 | MockWrite("GET / HTTP/1.1\r\n" |
| 2547 | "Host: www.borked.com\r\n" |
| 2548 | "Connection: keep-alive\r\n\r\n"), |
| 2549 | }; |
| 2550 | |
| 2551 | MockRead data_reads1[] = { |
| 2552 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2553 | "Connection: keep-alive\r\n" |
| 2554 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2555 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2556 | MockRead("0\r\n\r\nBonus data!"), |
| 2557 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2558 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2559 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2560 | |
| 2561 | TestCompletionCallback callback; |
| 2562 | HttpRequestInfo request1; |
| 2563 | request1.method = "GET"; |
| 2564 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2565 | request1.traffic_annotation = |
| 2566 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2567 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2568 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2569 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2570 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2571 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2572 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2573 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2574 | ASSERT_TRUE(response1); |
| 2575 | ASSERT_TRUE(response1->headers); |
| 2576 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2577 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2578 | |
| 2579 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2580 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2581 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2582 | |
| 2583 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2584 | // socket can't be reused, rather than returning it to the socket pool. |
| 2585 | base::RunLoop().RunUntilIdle(); |
| 2586 | |
| 2587 | // There should be no idle sockets in the pool. |
| 2588 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2589 | } |
| 2590 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2591 | // Test the request-challenge-retry sequence for basic auth. |
| 2592 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2593 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2594 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2595 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2596 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2597 | request.traffic_annotation = |
| 2598 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2599 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2600 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2601 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2602 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2603 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2604 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2605 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2606 | MockWrite( |
| 2607 | "GET / HTTP/1.1\r\n" |
| 2608 | "Host: www.example.org\r\n" |
| 2609 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2610 | }; |
| 2611 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2612 | MockRead data_reads1[] = { |
| 2613 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2614 | // Give a couple authenticate options (only the middle one is actually |
| 2615 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2616 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2617 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2618 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2619 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2620 | // Large content-length -- won't matter, as connection will be reset. |
| 2621 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2622 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2623 | }; |
| 2624 | |
| 2625 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2626 | // be issuing -- the final header line contains the credentials. |
| 2627 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2628 | MockWrite( |
| 2629 | "GET / HTTP/1.1\r\n" |
| 2630 | "Host: www.example.org\r\n" |
| 2631 | "Connection: keep-alive\r\n" |
| 2632 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2633 | }; |
| 2634 | |
| 2635 | // Lastly, the server responds with the actual content. |
| 2636 | MockRead data_reads2[] = { |
| 2637 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2638 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2639 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2640 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2641 | }; |
| 2642 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2643 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2644 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2645 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2646 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2647 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2648 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2649 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2650 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2651 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2652 | |
| 2653 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2654 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2655 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2656 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2657 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2658 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2659 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2660 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2661 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2662 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2663 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2664 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2665 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2666 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2667 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2668 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2669 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2670 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2671 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2672 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2673 | |
| 2674 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2675 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2676 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2677 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2678 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2679 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2680 | // The load timing after restart should have a new socket ID, and times after |
| 2681 | // those of the first load timing. |
| 2682 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2683 | load_timing_info2.connect_timing.connect_start); |
| 2684 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2685 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2686 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2687 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2688 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2689 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2690 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2691 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2692 | ASSERT_TRUE(response); |
| 2693 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2694 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2695 | } |
| 2696 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2697 | // Test the request-challenge-retry sequence for basic auth. |
| 2698 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2699 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2700 | HttpRequestInfo request; |
| 2701 | request.method = "GET"; |
| 2702 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2703 | request.traffic_annotation = |
| 2704 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2705 | |
| 2706 | TestNetLog log; |
| 2707 | MockHostResolver* resolver = new MockHostResolver(); |
| 2708 | session_deps_.net_log = &log; |
| 2709 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2710 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2711 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2712 | |
| 2713 | resolver->rules()->ClearRules(); |
| 2714 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2715 | |
| 2716 | MockWrite data_writes1[] = { |
| 2717 | MockWrite("GET / HTTP/1.1\r\n" |
| 2718 | "Host: www.example.org\r\n" |
| 2719 | "Connection: keep-alive\r\n\r\n"), |
| 2720 | }; |
| 2721 | |
| 2722 | MockRead data_reads1[] = { |
| 2723 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2724 | // Give a couple authenticate options (only the middle one is actually |
| 2725 | // supported). |
| 2726 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2727 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2728 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2729 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2730 | // Large content-length -- won't matter, as connection will be reset. |
| 2731 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2732 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2733 | }; |
| 2734 | |
| 2735 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2736 | // be issuing -- the final header line contains the credentials. |
| 2737 | MockWrite data_writes2[] = { |
| 2738 | MockWrite("GET / HTTP/1.1\r\n" |
| 2739 | "Host: www.example.org\r\n" |
| 2740 | "Connection: keep-alive\r\n" |
| 2741 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2742 | }; |
| 2743 | |
| 2744 | // Lastly, the server responds with the actual content. |
| 2745 | MockRead data_reads2[] = { |
| 2746 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2747 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2748 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2749 | }; |
| 2750 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2751 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2752 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2753 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2754 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2755 | |
| 2756 | TestCompletionCallback callback1; |
| 2757 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2758 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2759 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2760 | |
| 2761 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2762 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2763 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2764 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2765 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2766 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2767 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2768 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2769 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2770 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2771 | ASSERT_TRUE(response); |
| 2772 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2773 | |
| 2774 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2775 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2776 | ASSERT_FALSE(endpoint.address().empty()); |
| 2777 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2778 | |
| 2779 | resolver->rules()->ClearRules(); |
| 2780 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2781 | |
| 2782 | TestCompletionCallback callback2; |
| 2783 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2784 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2785 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2786 | |
| 2787 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2788 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2789 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2790 | // The load timing after restart should have a new socket ID, and times after |
| 2791 | // those of the first load timing. |
| 2792 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2793 | load_timing_info2.connect_timing.connect_start); |
| 2794 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2795 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2796 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2797 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2798 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2799 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2800 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2801 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2802 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2803 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2804 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2805 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2806 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2807 | ASSERT_FALSE(endpoint.address().empty()); |
| 2808 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2809 | } |
| 2810 | |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2811 | // Test that, if the server requests auth indefinitely, HttpNetworkTransaction |
| 2812 | // will eventually give up. |
| 2813 | TEST_F(HttpNetworkTransactionTest, BasicAuthForever) { |
| 2814 | HttpRequestInfo request; |
| 2815 | request.method = "GET"; |
| 2816 | request.url = GURL("http://www.example.org/"); |
| 2817 | request.traffic_annotation = |
| 2818 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2819 | |
| 2820 | TestNetLog log; |
| 2821 | session_deps_.net_log = &log; |
| 2822 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2823 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 2824 | |
| 2825 | MockWrite data_writes[] = { |
| 2826 | MockWrite("GET / HTTP/1.1\r\n" |
| 2827 | "Host: www.example.org\r\n" |
| 2828 | "Connection: keep-alive\r\n\r\n"), |
| 2829 | }; |
| 2830 | |
| 2831 | MockRead data_reads[] = { |
| 2832 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2833 | // Give a couple authenticate options (only the middle one is actually |
| 2834 | // supported). |
| 2835 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2836 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2837 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2838 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2839 | // Large content-length -- won't matter, as connection will be reset. |
| 2840 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2841 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2842 | }; |
| 2843 | |
| 2844 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2845 | // be issuing -- the final header line contains the credentials. |
| 2846 | MockWrite data_writes_restart[] = { |
| 2847 | MockWrite("GET / HTTP/1.1\r\n" |
| 2848 | "Host: www.example.org\r\n" |
| 2849 | "Connection: keep-alive\r\n" |
| 2850 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2851 | }; |
| 2852 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2853 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2854 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2855 | |
| 2856 | TestCompletionCallback callback; |
| 2857 | int rv = callback.GetResult( |
| 2858 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 2859 | |
| 2860 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_restarts; |
| 2861 | for (int i = 0; i < 32; i++) { |
| 2862 | // Check the previous response was a 401. |
| 2863 | EXPECT_THAT(rv, IsOk()); |
| 2864 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 2865 | ASSERT_TRUE(response); |
| 2866 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2867 | |
| 2868 | data_restarts.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2869 | data_reads, data_writes_restart)); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2870 | session_deps_.socket_factory->AddSocketDataProvider( |
| 2871 | data_restarts.back().get()); |
| 2872 | rv = callback.GetResult(trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2873 | callback.callback())); |
| 2874 | } |
| 2875 | |
| 2876 | // After too many tries, the transaction should have given up. |
| 2877 | EXPECT_THAT(rv, IsError(ERR_TOO_MANY_RETRIES)); |
| 2878 | } |
| 2879 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2880 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2881 | HttpRequestInfo request; |
| 2882 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2883 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2884 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2885 | request.traffic_annotation = |
| 2886 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2887 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2888 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2889 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2890 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2891 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2892 | MockWrite( |
| 2893 | "GET / HTTP/1.1\r\n" |
| 2894 | "Host: www.example.org\r\n" |
| 2895 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2896 | }; |
| 2897 | |
| 2898 | MockRead data_reads[] = { |
| 2899 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2900 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2901 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2902 | // Large content-length -- won't matter, as connection will be reset. |
| 2903 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2904 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2905 | }; |
| 2906 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2907 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2908 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2909 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2910 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2911 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2912 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2913 | |
| 2914 | rv = callback.WaitForResult(); |
| 2915 | EXPECT_EQ(0, rv); |
| 2916 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2917 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2918 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2919 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2920 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2921 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2922 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2923 | ASSERT_TRUE(response); |
| 2924 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2925 | } |
| 2926 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2927 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2928 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2929 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2930 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2931 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2932 | // reused. See http://crbug.com/544255. |
| 2933 | for (int i = 0; i < 2; ++i) { |
| 2934 | HttpRequestInfo request; |
| 2935 | request.method = "GET"; |
| 2936 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2937 | request.traffic_annotation = |
| 2938 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2939 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2940 | TestNetLog log; |
| 2941 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2942 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2943 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2944 | MockWrite data_writes[] = { |
| 2945 | MockWrite(ASYNC, 0, |
| 2946 | "GET / HTTP/1.1\r\n" |
| 2947 | "Host: www.example.org\r\n" |
| 2948 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2949 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2950 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2951 | // be issuing -- the final header line contains the credentials. |
| 2952 | MockWrite(ASYNC, 6, |
| 2953 | "GET / HTTP/1.1\r\n" |
| 2954 | "Host: www.example.org\r\n" |
| 2955 | "Connection: keep-alive\r\n" |
| 2956 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2957 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2958 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2959 | MockRead data_reads[] = { |
| 2960 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2961 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2962 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2963 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2964 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2965 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2966 | // Lastly, the server responds with the actual content. |
| 2967 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2968 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2969 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2970 | MockRead(ASYNC, 10, "Hello"), |
| 2971 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2972 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2973 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2974 | data.set_busy_before_sync_reads(true); |
| 2975 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2976 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2977 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2978 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2979 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2980 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2981 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2982 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2983 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2984 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2985 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2986 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2987 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2988 | ASSERT_TRUE(response); |
| 2989 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2990 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2991 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2992 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2993 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2994 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2995 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2996 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2997 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2998 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2999 | TestLoadTimingReused(load_timing_info2); |
| 3000 | // The load timing after restart should have the same socket ID, and times |
| 3001 | // those of the first load timing. |
| 3002 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 3003 | load_timing_info2.send_start); |
| 3004 | 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] | 3005 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3006 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3007 | ASSERT_TRUE(response); |
| 3008 | EXPECT_FALSE(response->auth_challenge); |
| 3009 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3010 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3011 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3012 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3013 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3014 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3015 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3016 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3017 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3018 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3019 | } |
| 3020 | |
| 3021 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3022 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3023 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3024 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3025 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3026 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3027 | request.traffic_annotation = |
| 3028 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3029 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3030 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3031 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3032 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3033 | MockWrite("GET / HTTP/1.1\r\n" |
| 3034 | "Host: www.example.org\r\n" |
| 3035 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3036 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3037 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3038 | // be issuing -- the final header line contains the credentials. |
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" |
| 3042 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3043 | }; |
| 3044 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3045 | MockRead data_reads1[] = { |
| 3046 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3047 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3048 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3049 | |
| 3050 | // Lastly, the server responds with the actual content. |
| 3051 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3052 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3053 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3054 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3055 | }; |
| 3056 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3057 | // An incorrect reconnect would cause this to be read. |
| 3058 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3059 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3060 | }; |
| 3061 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3062 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3063 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3064 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3065 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3066 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3067 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3068 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3069 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3070 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3071 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3072 | |
| 3073 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3074 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3075 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3076 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3077 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3078 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3079 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3080 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3081 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3082 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3083 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3084 | |
| 3085 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3086 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3087 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3088 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3089 | ASSERT_TRUE(response); |
| 3090 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3091 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3092 | } |
| 3093 | |
| 3094 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3095 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3096 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3097 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3098 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3099 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3100 | request.traffic_annotation = |
| 3101 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3102 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3103 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3104 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3105 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3106 | MockWrite("GET / HTTP/1.1\r\n" |
| 3107 | "Host: www.example.org\r\n" |
| 3108 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3109 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3110 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3111 | // be issuing -- the final header line contains the credentials. |
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" |
| 3115 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3116 | }; |
| 3117 | |
| 3118 | // Respond with 5 kb of response body. |
| 3119 | std::string large_body_string("Unauthorized"); |
| 3120 | large_body_string.append(5 * 1024, ' '); |
| 3121 | large_body_string.append("\r\n"); |
| 3122 | |
| 3123 | MockRead data_reads1[] = { |
| 3124 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3125 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3126 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3127 | // 5134 = 12 + 5 * 1024 + 2 |
| 3128 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3129 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3130 | |
| 3131 | // Lastly, the server responds with the actual content. |
| 3132 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3133 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3134 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3135 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3136 | }; |
| 3137 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3138 | // An incorrect reconnect would cause this to be read. |
| 3139 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3140 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3141 | }; |
| 3142 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3143 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3144 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3145 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3146 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3147 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3148 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3149 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3150 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3151 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3152 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3153 | |
| 3154 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3155 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3156 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3157 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3158 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3159 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3160 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3161 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3162 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3163 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3164 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3165 | |
| 3166 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3167 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3168 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3169 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3170 | ASSERT_TRUE(response); |
| 3171 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3172 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3173 | } |
| 3174 | |
| 3175 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3176 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3177 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3178 | HttpRequestInfo request; |
| 3179 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3180 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3181 | request.traffic_annotation = |
| 3182 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3183 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3184 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3185 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3186 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3187 | MockWrite( |
| 3188 | "GET / HTTP/1.1\r\n" |
| 3189 | "Host: www.example.org\r\n" |
| 3190 | "Connection: keep-alive\r\n\r\n"), |
| 3191 | // This simulates the seemingly successful write to a closed connection |
| 3192 | // if the bug is not fixed. |
| 3193 | MockWrite( |
| 3194 | "GET / HTTP/1.1\r\n" |
| 3195 | "Host: www.example.org\r\n" |
| 3196 | "Connection: keep-alive\r\n" |
| 3197 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3198 | }; |
| 3199 | |
| 3200 | MockRead data_reads1[] = { |
| 3201 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3202 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3203 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3204 | MockRead("Content-Length: 14\r\n\r\n"), |
| 3205 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3206 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3207 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3208 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3209 | }; |
| 3210 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3211 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3212 | // be issuing -- the final header line contains the credentials. |
| 3213 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3214 | MockWrite( |
| 3215 | "GET / HTTP/1.1\r\n" |
| 3216 | "Host: www.example.org\r\n" |
| 3217 | "Connection: keep-alive\r\n" |
| 3218 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3219 | }; |
| 3220 | |
| 3221 | // Lastly, the server responds with the actual content. |
| 3222 | MockRead data_reads2[] = { |
| 3223 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3224 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3225 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3226 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3227 | }; |
| 3228 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3229 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3230 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3231 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3232 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3233 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3234 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3235 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3236 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3237 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3238 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3239 | |
| 3240 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3241 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3242 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3243 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3244 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3245 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3246 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3247 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3248 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3249 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3250 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3251 | |
| 3252 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3253 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3254 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3255 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3256 | ASSERT_TRUE(response); |
| 3257 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3258 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3259 | } |
| 3260 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3261 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3262 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3263 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3264 | HttpRequestInfo request; |
| 3265 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3266 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3267 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3268 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3269 | request.traffic_annotation = |
| 3270 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3271 | |
| 3272 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3273 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3274 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3275 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3276 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3277 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3278 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3279 | |
| 3280 | // Since we have proxy, should try to establish tunnel. |
| 3281 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3282 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3283 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3284 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3285 | }; |
| 3286 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3287 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3288 | // connection. |
| 3289 | MockRead data_reads1[] = { |
| 3290 | // No credentials. |
| 3291 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3292 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3293 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3294 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3295 | // Since the first connection couldn't be reused, need to establish another |
| 3296 | // once given credentials. |
| 3297 | MockWrite data_writes2[] = { |
| 3298 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3299 | // be issuing -- the final header line contains the credentials. |
| 3300 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3301 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3302 | "Proxy-Connection: keep-alive\r\n" |
| 3303 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3304 | |
| 3305 | MockWrite("GET / HTTP/1.1\r\n" |
| 3306 | "Host: www.example.org\r\n" |
| 3307 | "Connection: keep-alive\r\n\r\n"), |
| 3308 | }; |
| 3309 | |
| 3310 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3311 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3312 | |
| 3313 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3314 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3315 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3316 | MockRead(SYNCHRONOUS, "hello"), |
| 3317 | }; |
| 3318 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3319 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3320 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3321 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3322 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3323 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3324 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3325 | |
| 3326 | TestCompletionCallback callback1; |
| 3327 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3328 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3329 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3330 | |
| 3331 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3332 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3333 | |
| 3334 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3335 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3336 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3337 | log.GetEntries(&entries); |
| 3338 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3339 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3340 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3341 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3342 | entries, pos, |
| 3343 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3344 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3345 | |
| 3346 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3347 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3348 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3349 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3350 | EXPECT_EQ(407, response->headers->response_code()); |
| 3351 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3352 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3353 | |
| 3354 | LoadTimingInfo load_timing_info; |
| 3355 | // CONNECT requests and responses are handled at the connect job level, so |
| 3356 | // the transaction does not yet have a connection. |
| 3357 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3358 | |
| 3359 | TestCompletionCallback callback2; |
| 3360 | |
| 3361 | rv = |
| 3362 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3363 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3364 | |
| 3365 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3366 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3367 | |
| 3368 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3369 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3370 | |
| 3371 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3372 | EXPECT_EQ(200, response->headers->response_code()); |
| 3373 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3374 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3375 | |
| 3376 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3377 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3378 | |
| 3379 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3380 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3381 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3382 | |
| 3383 | trans.reset(); |
| 3384 | session->CloseAllConnections(); |
| 3385 | } |
| 3386 | |
| 3387 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3388 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3389 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3390 | HttpRequestInfo request; |
| 3391 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3392 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3393 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3394 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3395 | request.traffic_annotation = |
| 3396 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3397 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3398 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3399 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3400 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3401 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3402 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3403 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3404 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3405 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3406 | // Since we have proxy, should try to establish tunnel. |
| 3407 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3408 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3409 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3410 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3411 | }; |
| 3412 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3413 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3414 | // connection. |
| 3415 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3416 | // No credentials. |
| 3417 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3418 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3419 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3420 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3421 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3422 | MockWrite data_writes2[] = { |
| 3423 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3424 | // be issuing -- the final header line contains the credentials. |
| 3425 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3426 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3427 | "Proxy-Connection: keep-alive\r\n" |
| 3428 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3429 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3430 | MockWrite("GET / HTTP/1.1\r\n" |
| 3431 | "Host: www.example.org\r\n" |
| 3432 | "Connection: keep-alive\r\n\r\n"), |
| 3433 | }; |
| 3434 | |
| 3435 | MockRead data_reads2[] = { |
| 3436 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3437 | |
| 3438 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3439 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3440 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3441 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3442 | }; |
| 3443 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3444 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3445 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3446 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3447 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3448 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3449 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3450 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3451 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3452 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3453 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3454 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3455 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3456 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3457 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3458 | |
| 3459 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3460 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3461 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3462 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3463 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3464 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3465 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3466 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3467 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3468 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3469 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3470 | |
| 3471 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3472 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3473 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3474 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3475 | EXPECT_EQ(407, response->headers->response_code()); |
| 3476 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3477 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3478 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3479 | LoadTimingInfo load_timing_info; |
| 3480 | // CONNECT requests and responses are handled at the connect job level, so |
| 3481 | // the transaction does not yet have a connection. |
| 3482 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3483 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3484 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3485 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3486 | rv = trans->RestartWithAuth( |
| 3487 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3488 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3489 | |
| 3490 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3491 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3492 | |
| 3493 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3494 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3495 | |
| 3496 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3497 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3498 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3499 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3500 | |
| 3501 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3502 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3503 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3504 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3505 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3506 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3507 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3508 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3509 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3510 | } |
| 3511 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3512 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3513 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3514 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3515 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3516 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3517 | // reused. See http://crbug.com/544255. |
| 3518 | for (int i = 0; i < 2; ++i) { |
| 3519 | HttpRequestInfo request; |
| 3520 | request.method = "GET"; |
| 3521 | request.url = GURL("https://www.example.org/"); |
| 3522 | // Ensure that proxy authentication is attempted even |
| 3523 | // when the no authentication data flag is set. |
| 3524 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3525 | request.traffic_annotation = |
| 3526 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3527 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3528 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3529 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3530 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3531 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3532 | BoundTestNetLog log; |
| 3533 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3534 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3535 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3536 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3537 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3538 | // Since we have proxy, should try to establish tunnel. |
| 3539 | MockWrite data_writes1[] = { |
| 3540 | MockWrite(ASYNC, 0, |
| 3541 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3542 | "Host: www.example.org:443\r\n" |
| 3543 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3544 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3545 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3546 | // be issuing -- the final header line contains the credentials. |
| 3547 | MockWrite(ASYNC, 3, |
| 3548 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3549 | "Host: www.example.org:443\r\n" |
| 3550 | "Proxy-Connection: keep-alive\r\n" |
| 3551 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3552 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3553 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3554 | // The proxy responds to the connect with a 407, using a persistent |
| 3555 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3556 | MockRead data_reads1[] = { |
| 3557 | // No credentials. |
| 3558 | MockRead(ASYNC, 1, |
| 3559 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3560 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3561 | "Proxy-Connection: keep-alive\r\n" |
| 3562 | "Content-Length: 10\r\n\r\n"), |
| 3563 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3564 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3565 | // Wrong credentials (wrong password). |
| 3566 | MockRead(ASYNC, 4, |
| 3567 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3568 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3569 | "Proxy-Connection: keep-alive\r\n" |
| 3570 | "Content-Length: 10\r\n\r\n"), |
| 3571 | // No response body because the test stops reading here. |
| 3572 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3573 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3574 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3575 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3576 | data1.set_busy_before_sync_reads(true); |
| 3577 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3578 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3579 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3580 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3581 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3582 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3583 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3584 | TestNetLogEntry::List entries; |
| 3585 | log.GetEntries(&entries); |
| 3586 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3587 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3588 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3589 | ExpectLogContainsSomewhere( |
| 3590 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3591 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3592 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3593 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3594 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3595 | ASSERT_TRUE(response); |
| 3596 | ASSERT_TRUE(response->headers); |
| 3597 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3598 | EXPECT_EQ(407, response->headers->response_code()); |
| 3599 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3600 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3601 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3602 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3603 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3604 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3605 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3606 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3607 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3608 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3609 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3610 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3611 | ASSERT_TRUE(response); |
| 3612 | ASSERT_TRUE(response->headers); |
| 3613 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3614 | EXPECT_EQ(407, response->headers->response_code()); |
| 3615 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3616 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3617 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3618 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3619 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3620 | // out of scope. |
| 3621 | session->CloseAllConnections(); |
| 3622 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3623 | } |
| 3624 | |
| 3625 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3626 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3627 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3628 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3629 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3630 | // reused. See http://crbug.com/544255. |
| 3631 | for (int i = 0; i < 2; ++i) { |
| 3632 | HttpRequestInfo request; |
| 3633 | request.method = "GET"; |
| 3634 | request.url = GURL("https://www.example.org/"); |
| 3635 | // Ensure that proxy authentication is attempted even |
| 3636 | // when the no authentication data flag is set. |
| 3637 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3638 | request.traffic_annotation = |
| 3639 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3640 | |
| 3641 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3642 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3643 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3644 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3645 | BoundTestNetLog log; |
| 3646 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3647 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3648 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3649 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3650 | |
| 3651 | // Since we have proxy, should try to establish tunnel. |
| 3652 | MockWrite data_writes1[] = { |
| 3653 | MockWrite(ASYNC, 0, |
| 3654 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3655 | "Host: www.example.org:443\r\n" |
| 3656 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3657 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3658 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3659 | // be issuing -- the final header line contains the credentials. |
| 3660 | MockWrite(ASYNC, 3, |
| 3661 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3662 | "Host: www.example.org:443\r\n" |
| 3663 | "Proxy-Connection: keep-alive\r\n" |
| 3664 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3665 | }; |
| 3666 | |
| 3667 | // The proxy responds to the connect with a 407, using a persistent |
| 3668 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3669 | MockRead data_reads1[] = { |
| 3670 | // No credentials. |
| 3671 | MockRead(ASYNC, 1, |
| 3672 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3673 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3674 | "Content-Length: 10\r\n\r\n"), |
| 3675 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3676 | |
| 3677 | // Wrong credentials (wrong password). |
| 3678 | MockRead(ASYNC, 4, |
| 3679 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3680 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3681 | "Content-Length: 10\r\n\r\n"), |
| 3682 | // No response body because the test stops reading here. |
| 3683 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3684 | }; |
| 3685 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3686 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3687 | data1.set_busy_before_sync_reads(true); |
| 3688 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3689 | |
| 3690 | TestCompletionCallback callback1; |
| 3691 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3692 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3693 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3694 | |
| 3695 | TestNetLogEntry::List entries; |
| 3696 | log.GetEntries(&entries); |
| 3697 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3698 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3699 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3700 | ExpectLogContainsSomewhere( |
| 3701 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3702 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3703 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3704 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3705 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3706 | ASSERT_TRUE(response); |
| 3707 | ASSERT_TRUE(response->headers); |
| 3708 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3709 | EXPECT_EQ(407, response->headers->response_code()); |
| 3710 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3711 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3712 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame^] | 3713 | EXPECT_FALSE(response->did_use_http_auth); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3714 | |
| 3715 | TestCompletionCallback callback2; |
| 3716 | |
| 3717 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3718 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3719 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3720 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3721 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3722 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3723 | ASSERT_TRUE(response); |
| 3724 | ASSERT_TRUE(response->headers); |
| 3725 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3726 | EXPECT_EQ(407, response->headers->response_code()); |
| 3727 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3728 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3729 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame^] | 3730 | EXPECT_TRUE(response->did_use_http_auth); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3731 | |
| 3732 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3733 | // out of scope. |
| 3734 | session->CloseAllConnections(); |
| 3735 | } |
| 3736 | } |
| 3737 | |
| 3738 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3739 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3740 | // the case the server sends extra data on the original socket, so it can't be |
| 3741 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3742 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3743 | HttpRequestInfo request; |
| 3744 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3745 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3746 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3747 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3748 | request.traffic_annotation = |
| 3749 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3750 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3751 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3752 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3753 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3754 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3755 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3756 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3757 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3758 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3759 | // Since we have proxy, should try to establish tunnel. |
| 3760 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3761 | MockWrite(ASYNC, 0, |
| 3762 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3763 | "Host: www.example.org:443\r\n" |
| 3764 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3765 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3766 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3767 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3768 | // extra data, so the socket cannot be reused. |
| 3769 | MockRead data_reads1[] = { |
| 3770 | // No credentials. |
| 3771 | MockRead(ASYNC, 1, |
| 3772 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3773 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3774 | "Content-Length: 10\r\n\r\n"), |
| 3775 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3776 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3777 | }; |
| 3778 | |
| 3779 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3780 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3781 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3782 | MockWrite(ASYNC, 0, |
| 3783 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3784 | "Host: www.example.org:443\r\n" |
| 3785 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3786 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3787 | |
| 3788 | MockWrite(ASYNC, 2, |
| 3789 | "GET / HTTP/1.1\r\n" |
| 3790 | "Host: www.example.org\r\n" |
| 3791 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3792 | }; |
| 3793 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3794 | MockRead data_reads2[] = { |
| 3795 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3796 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3797 | MockRead(ASYNC, 3, |
| 3798 | "HTTP/1.1 200 OK\r\n" |
| 3799 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3800 | "Content-Length: 5\r\n\r\n"), |
| 3801 | // No response body because the test stops reading here. |
| 3802 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3803 | }; |
| 3804 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3805 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3806 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3807 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3808 | SequencedSocketData data2(data_reads2, data_writes2); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3809 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3810 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3811 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3812 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3813 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3814 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3815 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3816 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3817 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3818 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3819 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3820 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3821 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3822 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3823 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3824 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3825 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3826 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3827 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3828 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3829 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3830 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3831 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3832 | ASSERT_TRUE(response); |
| 3833 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3834 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3835 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3836 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3837 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3838 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3839 | LoadTimingInfo load_timing_info; |
| 3840 | // CONNECT requests and responses are handled at the connect job level, so |
| 3841 | // the transaction does not yet have a connection. |
| 3842 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3843 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3844 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3845 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3846 | rv = |
| 3847 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3848 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3849 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3850 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3851 | EXPECT_EQ(200, response->headers->response_code()); |
| 3852 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3853 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3854 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3855 | // The password prompt info should not be set. |
| 3856 | EXPECT_FALSE(response->auth_challenge); |
| 3857 | |
| 3858 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3859 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3860 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3861 | |
| 3862 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3863 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3864 | } |
| 3865 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3866 | // Test the case a proxy closes a socket while the challenge body is being |
| 3867 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3868 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3869 | HttpRequestInfo request; |
| 3870 | request.method = "GET"; |
| 3871 | request.url = GURL("https://www.example.org/"); |
| 3872 | // Ensure that proxy authentication is attempted even |
| 3873 | // when the no authentication data flag is set. |
| 3874 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3875 | request.traffic_annotation = |
| 3876 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3877 | |
| 3878 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3879 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3880 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3881 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3882 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3883 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3884 | |
| 3885 | // Since we have proxy, should try to establish tunnel. |
| 3886 | MockWrite data_writes1[] = { |
| 3887 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3888 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3889 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3890 | }; |
| 3891 | |
| 3892 | // The proxy responds to the connect with a 407, using a persistent |
| 3893 | // connection. |
| 3894 | MockRead data_reads1[] = { |
| 3895 | // No credentials. |
| 3896 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3897 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3898 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3899 | // Server hands up in the middle of the body. |
| 3900 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3901 | }; |
| 3902 | |
| 3903 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3904 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3905 | // be issuing -- the final header line contains the credentials. |
| 3906 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3907 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3908 | "Proxy-Connection: keep-alive\r\n" |
| 3909 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3910 | |
| 3911 | MockWrite("GET / HTTP/1.1\r\n" |
| 3912 | "Host: www.example.org\r\n" |
| 3913 | "Connection: keep-alive\r\n\r\n"), |
| 3914 | }; |
| 3915 | |
| 3916 | MockRead data_reads2[] = { |
| 3917 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3918 | |
| 3919 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3920 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3921 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3922 | MockRead(SYNCHRONOUS, "hello"), |
| 3923 | }; |
| 3924 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3925 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3926 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3927 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3928 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3929 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3930 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3931 | |
| 3932 | TestCompletionCallback callback; |
| 3933 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3934 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3935 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3936 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3937 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3938 | ASSERT_TRUE(response); |
| 3939 | ASSERT_TRUE(response->headers); |
| 3940 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3941 | EXPECT_EQ(407, response->headers->response_code()); |
| 3942 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3943 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3944 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3945 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3946 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3947 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3948 | ASSERT_TRUE(response); |
| 3949 | ASSERT_TRUE(response->headers); |
| 3950 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3951 | EXPECT_EQ(200, response->headers->response_code()); |
| 3952 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3953 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3954 | EXPECT_EQ("hello", body); |
| 3955 | } |
| 3956 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3957 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3958 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3959 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3960 | HttpRequestInfo request; |
| 3961 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3962 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3963 | request.traffic_annotation = |
| 3964 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3965 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3966 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3967 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3968 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3969 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3970 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3971 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3972 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3973 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3974 | // Since we have proxy, should try to establish tunnel. |
| 3975 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3976 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3977 | "Host: www.example.org:443\r\n" |
| 3978 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3979 | }; |
| 3980 | |
| 3981 | // The proxy responds to the connect with a 407. |
| 3982 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3983 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3984 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3985 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3986 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3987 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3988 | }; |
| 3989 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3990 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3991 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3992 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3993 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3994 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3995 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3996 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3997 | |
| 3998 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3999 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4000 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4001 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4002 | ASSERT_TRUE(response); |
| 4003 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4004 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4005 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4006 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4007 | |
| 4008 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4009 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4010 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 4011 | |
| 4012 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 4013 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4014 | } |
| 4015 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4016 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 4017 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4018 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4019 | HttpRequestInfo request; |
| 4020 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4021 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4022 | request.traffic_annotation = |
| 4023 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4024 | |
| 4025 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4026 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4027 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4028 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4029 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4030 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4031 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4032 | |
| 4033 | // Since we have proxy, should try to establish tunnel. |
| 4034 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4035 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4036 | "Host: www.example.org:443\r\n" |
| 4037 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4038 | }; |
| 4039 | |
| 4040 | // The proxy responds to the connect with a 407. |
| 4041 | MockRead data_reads[] = { |
| 4042 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4043 | MockRead("X-Foo: bar\r\n"), |
| 4044 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 4045 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4046 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4047 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4048 | }; |
| 4049 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4050 | StaticSocketDataProvider data(data_reads, data_writes); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4051 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4052 | |
| 4053 | TestCompletionCallback callback; |
| 4054 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4055 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4056 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4057 | |
| 4058 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4059 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4060 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4061 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4062 | ASSERT_TRUE(response); |
| 4063 | ASSERT_TRUE(response->headers); |
| 4064 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4065 | EXPECT_EQ(407, response->headers->response_code()); |
| 4066 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4067 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 4068 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 4069 | |
| 4070 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4071 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4072 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4073 | |
| 4074 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 4075 | session->CloseAllConnections(); |
| 4076 | } |
| 4077 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4078 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 4079 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4080 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4081 | HttpRequestInfo request; |
| 4082 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4083 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4084 | request.traffic_annotation = |
| 4085 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4086 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4087 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4088 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4089 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4090 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4091 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4092 | MockWrite( |
| 4093 | "GET / HTTP/1.1\r\n" |
| 4094 | "Host: www.example.org\r\n" |
| 4095 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4096 | }; |
| 4097 | |
| 4098 | MockRead data_reads1[] = { |
| 4099 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 4100 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4101 | // Large content-length -- won't matter, as connection will be reset. |
| 4102 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4103 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4104 | }; |
| 4105 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4106 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4107 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4108 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4109 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4110 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4111 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4112 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4113 | |
| 4114 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4115 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4116 | } |
| 4117 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4118 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 4119 | // through a non-authenticating proxy. The request should fail with |
| 4120 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 4121 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 4122 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 4123 | // response came from the proxy or the server, so it is treated as if the proxy |
| 4124 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4125 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4126 | HttpRequestInfo request; |
| 4127 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4128 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4129 | request.traffic_annotation = |
| 4130 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4131 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4132 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4133 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4134 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4135 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4136 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4137 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4138 | // Since we have proxy, should try to establish tunnel. |
| 4139 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4140 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4141 | "Host: www.example.org:443\r\n" |
| 4142 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4143 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4144 | MockWrite("GET / HTTP/1.1\r\n" |
| 4145 | "Host: www.example.org\r\n" |
| 4146 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4147 | }; |
| 4148 | |
| 4149 | MockRead data_reads1[] = { |
| 4150 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4151 | |
| 4152 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 4153 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4154 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4155 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4156 | }; |
| 4157 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4158 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4159 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4160 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4161 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4162 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4163 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4164 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4165 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4166 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4167 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4168 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4169 | |
| 4170 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4171 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 4172 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4173 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4174 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4175 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 4176 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4177 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4178 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4179 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 4180 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4181 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4182 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4183 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4184 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4185 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4186 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 4187 | HttpRequestInfo request; |
| 4188 | request.method = "GET"; |
| 4189 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4190 | request.traffic_annotation = |
| 4191 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4192 | |
| 4193 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4194 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4195 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4196 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4197 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4198 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4199 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4200 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4201 | mock_handler->set_allows_default_credentials(true); |
| 4202 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4203 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4204 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4205 | |
| 4206 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4207 | NetLog net_log; |
| 4208 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4209 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4210 | |
| 4211 | // Since we have proxy, should try to establish tunnel. |
| 4212 | MockWrite data_writes1[] = { |
| 4213 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4214 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4215 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4216 | }; |
| 4217 | |
| 4218 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4219 | // connection. |
| 4220 | MockRead data_reads1[] = { |
| 4221 | // No credentials. |
| 4222 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4223 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4224 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4225 | }; |
| 4226 | |
| 4227 | // Since the first connection couldn't be reused, need to establish another |
| 4228 | // once given credentials. |
| 4229 | MockWrite data_writes2[] = { |
| 4230 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4231 | // be issuing -- the final header line contains the credentials. |
| 4232 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4233 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4234 | "Proxy-Connection: keep-alive\r\n" |
| 4235 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4236 | |
| 4237 | MockWrite("GET / HTTP/1.1\r\n" |
| 4238 | "Host: www.example.org\r\n" |
| 4239 | "Connection: keep-alive\r\n\r\n"), |
| 4240 | }; |
| 4241 | |
| 4242 | MockRead data_reads2[] = { |
| 4243 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4244 | |
| 4245 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4246 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4247 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4248 | MockRead(SYNCHRONOUS, "hello"), |
| 4249 | }; |
| 4250 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4251 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4252 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4253 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4254 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4255 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4256 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4257 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4258 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4259 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4260 | |
| 4261 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4262 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4263 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4264 | |
| 4265 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4266 | ASSERT_TRUE(response); |
| 4267 | ASSERT_TRUE(response->headers); |
| 4268 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 4269 | EXPECT_EQ(407, response->headers->response_code()); |
| 4270 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4271 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4272 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4273 | |
| 4274 | LoadTimingInfo load_timing_info; |
| 4275 | // CONNECT requests and responses are handled at the connect job level, so |
| 4276 | // the transaction does not yet have a connection. |
| 4277 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4278 | |
| 4279 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4280 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4281 | response = trans->GetResponseInfo(); |
| 4282 | ASSERT_TRUE(response); |
| 4283 | ASSERT_TRUE(response->headers); |
| 4284 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4285 | EXPECT_EQ(200, response->headers->response_code()); |
| 4286 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4287 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4288 | |
| 4289 | // The password prompt info should not be set. |
| 4290 | EXPECT_FALSE(response->auth_challenge); |
| 4291 | |
| 4292 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4293 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4294 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4295 | |
| 4296 | trans.reset(); |
| 4297 | session->CloseAllConnections(); |
| 4298 | } |
| 4299 | |
| 4300 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4301 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4302 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4303 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4304 | HttpRequestInfo request; |
| 4305 | request.method = "GET"; |
| 4306 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4307 | request.traffic_annotation = |
| 4308 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4309 | |
| 4310 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4311 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4312 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4313 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4314 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4315 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4316 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4317 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4318 | mock_handler->set_allows_default_credentials(true); |
| 4319 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4320 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4321 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4322 | |
| 4323 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4324 | NetLog net_log; |
| 4325 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4326 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4327 | |
| 4328 | // Should try to establish tunnel. |
| 4329 | MockWrite data_writes1[] = { |
| 4330 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4331 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4332 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4333 | |
| 4334 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4335 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4336 | "Proxy-Connection: keep-alive\r\n" |
| 4337 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4338 | }; |
| 4339 | |
| 4340 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4341 | // connection. |
| 4342 | MockRead data_reads1[] = { |
| 4343 | // No credentials. |
| 4344 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4345 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4346 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4347 | }; |
| 4348 | |
| 4349 | // Since the first connection was closed, need to establish another once given |
| 4350 | // credentials. |
| 4351 | MockWrite data_writes2[] = { |
| 4352 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4353 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4354 | "Proxy-Connection: keep-alive\r\n" |
| 4355 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4356 | |
| 4357 | MockWrite("GET / HTTP/1.1\r\n" |
| 4358 | "Host: www.example.org\r\n" |
| 4359 | "Connection: keep-alive\r\n\r\n"), |
| 4360 | }; |
| 4361 | |
| 4362 | MockRead data_reads2[] = { |
| 4363 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4364 | |
| 4365 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4366 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4367 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4368 | MockRead(SYNCHRONOUS, "hello"), |
| 4369 | }; |
| 4370 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4371 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4372 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4373 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4374 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4375 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4376 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4377 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4378 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4379 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4380 | |
| 4381 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4382 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4383 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4384 | |
| 4385 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4386 | ASSERT_TRUE(response); |
| 4387 | ASSERT_TRUE(response->headers); |
| 4388 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4389 | EXPECT_EQ(407, response->headers->response_code()); |
| 4390 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4391 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4392 | EXPECT_FALSE(response->auth_challenge); |
| 4393 | |
| 4394 | LoadTimingInfo load_timing_info; |
| 4395 | // CONNECT requests and responses are handled at the connect job level, so |
| 4396 | // the transaction does not yet have a connection. |
| 4397 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4398 | |
| 4399 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4400 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4401 | |
| 4402 | response = trans->GetResponseInfo(); |
| 4403 | ASSERT_TRUE(response); |
| 4404 | ASSERT_TRUE(response->headers); |
| 4405 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4406 | EXPECT_EQ(200, response->headers->response_code()); |
| 4407 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4408 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4409 | |
| 4410 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4411 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4412 | |
| 4413 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4414 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4415 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4416 | |
| 4417 | trans.reset(); |
| 4418 | session->CloseAllConnections(); |
| 4419 | } |
| 4420 | |
| 4421 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4422 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4423 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4424 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4425 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4426 | HttpRequestInfo request; |
| 4427 | request.method = "GET"; |
| 4428 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4429 | request.traffic_annotation = |
| 4430 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4431 | |
| 4432 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4433 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4434 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4435 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4436 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4437 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4438 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4439 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4440 | mock_handler->set_allows_default_credentials(true); |
| 4441 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4442 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4443 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4444 | |
| 4445 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4446 | NetLog net_log; |
| 4447 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4448 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4449 | |
| 4450 | // Should try to establish tunnel. |
| 4451 | MockWrite data_writes1[] = { |
| 4452 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4453 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4454 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4455 | |
| 4456 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4457 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4458 | "Proxy-Connection: keep-alive\r\n" |
| 4459 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4460 | }; |
| 4461 | |
| 4462 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4463 | // second request is sent. |
| 4464 | MockRead data_reads1[] = { |
| 4465 | // No credentials. |
| 4466 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4467 | MockRead("Content-Length: 0\r\n"), |
| 4468 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4469 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4470 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4471 | }; |
| 4472 | |
| 4473 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4474 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4475 | // request. |
| 4476 | MockWrite data_writes2[] = { |
| 4477 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4478 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4479 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4480 | }; |
| 4481 | |
| 4482 | // The proxy, having had more than enough of us, just hangs up. |
| 4483 | MockRead data_reads2[] = { |
| 4484 | // No credentials. |
| 4485 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4486 | }; |
| 4487 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4488 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4489 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4490 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4491 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4492 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4493 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4494 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4495 | |
| 4496 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4497 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4498 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4499 | |
| 4500 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4501 | ASSERT_TRUE(response); |
| 4502 | ASSERT_TRUE(response->headers); |
| 4503 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4504 | EXPECT_EQ(407, response->headers->response_code()); |
| 4505 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4506 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4507 | EXPECT_FALSE(response->auth_challenge); |
| 4508 | |
| 4509 | LoadTimingInfo load_timing_info; |
| 4510 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4511 | |
| 4512 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4513 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4514 | |
| 4515 | trans.reset(); |
| 4516 | session->CloseAllConnections(); |
| 4517 | } |
| 4518 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4519 | // This test exercises an odd edge case where the proxy closes the connection |
| 4520 | // after the authentication handshake is complete. Presumably this technique is |
| 4521 | // used in lieu of returning a 403 or 5xx status code when the authentication |
| 4522 | // succeeds, but the user is not authorized to connect to the destination |
| 4523 | // server. There's no standard for what a proxy should do to indicate a blocked |
| 4524 | // site. |
| 4525 | TEST_F(HttpNetworkTransactionTest, |
| 4526 | AuthAllowsDefaultCredentialsTunnelConnectionClosesBeforeBody) { |
| 4527 | HttpRequestInfo request; |
| 4528 | request.method = "GET"; |
| 4529 | request.url = GURL("https://www.example.org/"); |
| 4530 | request.traffic_annotation = |
| 4531 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4532 | |
| 4533 | // Configure against proxy server "myproxy:70". |
| 4534 | session_deps_.proxy_resolution_service = |
| 4535 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4536 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4537 | |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 4538 | // When TLS 1.3 is enabled, spurious connections are made as part of the SSL |
| 4539 | // version interference probes. |
| 4540 | // TODO(crbug.com/906668): Correctly handle version interference probes to |
| 4541 | // test TLS 1.3. |
| 4542 | SSLConfig config; |
| 4543 | config.version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
| 4544 | session_deps_.ssl_config_service = |
| 4545 | std::make_unique<TestSSLConfigService>(config); |
| 4546 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4547 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
| 4548 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4549 | |
| 4550 | // Create two mock AuthHandlers. This is because the transaction gets retried |
| 4551 | // after the first ERR_CONNECTION_CLOSED since it's ambiguous whether there |
| 4552 | // was a real network error. |
| 4553 | // |
| 4554 | // The handlers support both default and explicit credentials. The retry |
| 4555 | // mentioned above should be able to reuse the default identity. Thus there |
| 4556 | // should never be a need to prompt for explicit credentials. |
| 4557 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4558 | mock_handler->set_allows_default_credentials(true); |
| 4559 | mock_handler->set_allows_explicit_credentials(true); |
| 4560 | mock_handler->set_connection_based(true); |
| 4561 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4562 | HttpAuth::AUTH_PROXY); |
| 4563 | 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 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4570 | |
| 4571 | NetLog net_log; |
| 4572 | session_deps_.net_log = &net_log; |
| 4573 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4574 | |
| 4575 | // Data for both sockets. |
| 4576 | // |
| 4577 | // Writes are for the tunnel establishment attempts and the |
| 4578 | // authentication handshake. |
| 4579 | MockWrite data_writes1[] = { |
| 4580 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4581 | "Host: www.example.org:443\r\n" |
| 4582 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4583 | |
| 4584 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4585 | "Host: www.example.org:443\r\n" |
| 4586 | "Proxy-Connection: keep-alive\r\n" |
| 4587 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4588 | |
| 4589 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4590 | "Host: www.example.org:443\r\n" |
| 4591 | "Proxy-Connection: keep-alive\r\n" |
| 4592 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4593 | }; |
| 4594 | |
| 4595 | // The server side of the authentication handshake. Note that the response to |
| 4596 | // the final CONNECT request is ERR_CONNECTION_CLOSED. |
| 4597 | MockRead data_reads1[] = { |
| 4598 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4599 | MockRead("Content-Length: 0\r\n"), |
| 4600 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4601 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4602 | |
| 4603 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4604 | MockRead("Content-Length: 0\r\n"), |
| 4605 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4606 | MockRead("Proxy-Authenticate: Mock foo\r\n\r\n"), |
| 4607 | |
| 4608 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4609 | }; |
| 4610 | |
| 4611 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 4612 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4613 | |
| 4614 | // The second socket is for the reconnection attempt. Data is identical to the |
| 4615 | // first attempt. |
| 4616 | StaticSocketDataProvider data2(data_reads1, data_writes1); |
| 4617 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4618 | |
| 4619 | auto trans = |
| 4620 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4621 | |
| 4622 | TestCompletionCallback callback; |
| 4623 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4624 | |
| 4625 | // Two rounds per handshake. After one retry, the error is propagated up the |
| 4626 | // stack. |
| 4627 | for (int i = 0; i < 4; ++i) { |
| 4628 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4629 | |
| 4630 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4631 | ASSERT_TRUE(response); |
| 4632 | ASSERT_TRUE(response->headers); |
| 4633 | EXPECT_EQ(407, response->headers->response_code()); |
| 4634 | ASSERT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4635 | |
| 4636 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4637 | } |
| 4638 | |
| 4639 | // One shall be the number thou shalt retry, and the number of the retrying |
| 4640 | // shall be one. Two shalt thou not retry, neither retry thou zero, excepting |
| 4641 | // that thou then proceed to one. Three is right out. Once the number one, |
| 4642 | // being the first number, be reached, then lobbest thou thy |
| 4643 | // ERR_CONNECTION_CLOSED towards they network transaction, who shall snuff it. |
| 4644 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.GetResult(rv)); |
| 4645 | |
| 4646 | trans.reset(); |
| 4647 | session->CloseAllConnections(); |
| 4648 | } |
| 4649 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4650 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4651 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4652 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4653 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4654 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4655 | HttpRequestInfo request; |
| 4656 | request.method = "GET"; |
| 4657 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4658 | request.traffic_annotation = |
| 4659 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4660 | |
| 4661 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4662 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4663 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4664 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4665 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4666 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4667 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4668 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4669 | mock_handler->set_allows_default_credentials(true); |
| 4670 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4671 | HttpAuth::AUTH_PROXY); |
| 4672 | // Add another handler for the second challenge. It supports default |
| 4673 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4674 | 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); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4678 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4679 | |
| 4680 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4681 | NetLog net_log; |
| 4682 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4683 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4684 | |
| 4685 | // Should try to establish tunnel. |
| 4686 | MockWrite data_writes1[] = { |
| 4687 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4688 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4689 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4690 | }; |
| 4691 | |
| 4692 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4693 | // connection. |
| 4694 | MockRead data_reads1[] = { |
| 4695 | // No credentials. |
| 4696 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4697 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4698 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4699 | }; |
| 4700 | |
| 4701 | // Since the first connection was closed, need to establish another once given |
| 4702 | // credentials. |
| 4703 | MockWrite data_writes2[] = { |
| 4704 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4705 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4706 | "Proxy-Connection: keep-alive\r\n" |
| 4707 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4708 | }; |
| 4709 | |
| 4710 | MockRead data_reads2[] = { |
| 4711 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4712 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4713 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4714 | }; |
| 4715 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4716 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4717 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4718 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4719 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4720 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4721 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4722 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4723 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4724 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4725 | |
| 4726 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4727 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4728 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4729 | |
| 4730 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4731 | ASSERT_TRUE(response); |
| 4732 | ASSERT_TRUE(response->headers); |
| 4733 | EXPECT_EQ(407, response->headers->response_code()); |
| 4734 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4735 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4736 | EXPECT_FALSE(response->auth_challenge); |
| 4737 | |
| 4738 | LoadTimingInfo load_timing_info; |
| 4739 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4740 | |
| 4741 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4742 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4743 | response = trans->GetResponseInfo(); |
| 4744 | ASSERT_TRUE(response); |
| 4745 | ASSERT_TRUE(response->headers); |
| 4746 | EXPECT_EQ(407, response->headers->response_code()); |
| 4747 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4748 | EXPECT_TRUE(response->auth_challenge); |
| 4749 | |
| 4750 | trans.reset(); |
| 4751 | session->CloseAllConnections(); |
| 4752 | } |
| 4753 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4754 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4755 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4756 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4757 | // authentication handshake can continue with the same scheme but with a |
| 4758 | // different identity. |
| 4759 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4760 | HttpRequestInfo request; |
| 4761 | request.method = "GET"; |
| 4762 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4763 | request.traffic_annotation = |
| 4764 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4765 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4766 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4767 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4768 | |
| 4769 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4770 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4771 | mock_handler->set_allows_default_credentials(true); |
| 4772 | mock_handler->set_allows_explicit_credentials(true); |
| 4773 | mock_handler->set_connection_based(true); |
| 4774 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4775 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4776 | HttpAuth::AUTH_SERVER); |
| 4777 | |
| 4778 | // Add another handler for the second challenge. It supports default |
| 4779 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4780 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4781 | mock_handler->set_allows_default_credentials(true); |
| 4782 | mock_handler->set_allows_explicit_credentials(true); |
| 4783 | mock_handler->set_connection_based(true); |
| 4784 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4785 | HttpAuth::AUTH_SERVER); |
| 4786 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4787 | |
| 4788 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4789 | |
| 4790 | MockWrite data_writes1[] = { |
| 4791 | MockWrite("GET / HTTP/1.1\r\n" |
| 4792 | "Host: www.example.org\r\n" |
| 4793 | "Connection: keep-alive\r\n\r\n"), |
| 4794 | }; |
| 4795 | |
| 4796 | MockRead data_reads1[] = { |
| 4797 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4798 | "WWW-Authenticate: Mock\r\n" |
| 4799 | "Connection: keep-alive\r\n\r\n"), |
| 4800 | }; |
| 4801 | |
| 4802 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4803 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4804 | // transaction procceds without an authorization header. |
| 4805 | MockWrite data_writes2[] = { |
| 4806 | MockWrite("GET / HTTP/1.1\r\n" |
| 4807 | "Host: www.example.org\r\n" |
| 4808 | "Connection: keep-alive\r\n\r\n"), |
| 4809 | }; |
| 4810 | |
| 4811 | MockRead data_reads2[] = { |
| 4812 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4813 | "WWW-Authenticate: Mock\r\n" |
| 4814 | "Connection: keep-alive\r\n\r\n"), |
| 4815 | }; |
| 4816 | |
| 4817 | MockWrite data_writes3[] = { |
| 4818 | MockWrite("GET / HTTP/1.1\r\n" |
| 4819 | "Host: www.example.org\r\n" |
| 4820 | "Connection: keep-alive\r\n" |
| 4821 | "Authorization: auth_token\r\n\r\n"), |
| 4822 | }; |
| 4823 | |
| 4824 | MockRead data_reads3[] = { |
| 4825 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4826 | "Content-Length: 5\r\n" |
| 4827 | "Content-Type: text/plain\r\n" |
| 4828 | "Connection: keep-alive\r\n\r\n" |
| 4829 | "Hello"), |
| 4830 | }; |
| 4831 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4832 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4833 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4834 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4835 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4836 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4837 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4838 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4839 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4840 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4841 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4842 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4843 | |
| 4844 | TestCompletionCallback callback; |
| 4845 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4846 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4847 | |
| 4848 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4849 | ASSERT_TRUE(response); |
| 4850 | ASSERT_TRUE(response->headers); |
| 4851 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4852 | |
| 4853 | // The following three tests assert that an authentication challenge was |
| 4854 | // received and that the stack is ready to respond to the challenge using |
| 4855 | // ambient credentials. |
| 4856 | EXPECT_EQ(401, response->headers->response_code()); |
| 4857 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4858 | EXPECT_FALSE(response->auth_challenge); |
| 4859 | |
| 4860 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4861 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4862 | response = trans->GetResponseInfo(); |
| 4863 | ASSERT_TRUE(response); |
| 4864 | ASSERT_TRUE(response->headers); |
| 4865 | |
| 4866 | // The following three tests assert that an authentication challenge was |
| 4867 | // received and that the stack needs explicit credentials before it is ready |
| 4868 | // to respond to the challenge. |
| 4869 | EXPECT_EQ(401, response->headers->response_code()); |
| 4870 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4871 | EXPECT_TRUE(response->auth_challenge); |
| 4872 | |
| 4873 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4874 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4875 | response = trans->GetResponseInfo(); |
| 4876 | ASSERT_TRUE(response); |
| 4877 | ASSERT_TRUE(response->headers); |
| 4878 | EXPECT_EQ(200, response->headers->response_code()); |
| 4879 | |
| 4880 | trans.reset(); |
| 4881 | session->CloseAllConnections(); |
| 4882 | } |
| 4883 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4884 | // Proxy resolver that returns a proxy with the same host and port for different |
| 4885 | // schemes, based on the path of the URL being requests. |
| 4886 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 4887 | public: |
| 4888 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 4889 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 4890 | |
| 4891 | static std::string ProxyHostPortPairAsString() { return "proxy.test:10000"; } |
| 4892 | |
| 4893 | static HostPortPair ProxyHostPortPair() { |
| 4894 | return HostPortPair::FromString(ProxyHostPortPairAsString()); |
| 4895 | } |
| 4896 | |
| 4897 | // ProxyResolver implementation. |
| 4898 | int GetProxyForURL(const GURL& url, |
| 4899 | ProxyInfo* results, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4900 | CompletionOnceCallback callback, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4901 | std::unique_ptr<Request>* request, |
| 4902 | const NetLogWithSource& /*net_log*/) override { |
| 4903 | *results = ProxyInfo(); |
Ramin Halavati | 921731ea | 2018-03-16 08:24:57 | [diff] [blame] | 4904 | results->set_traffic_annotation( |
| 4905 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4906 | if (url.path() == "/socks4") { |
| 4907 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 4908 | return OK; |
| 4909 | } |
| 4910 | if (url.path() == "/socks5") { |
| 4911 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 4912 | return OK; |
| 4913 | } |
| 4914 | if (url.path() == "/http") { |
| 4915 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 4916 | return OK; |
| 4917 | } |
| 4918 | if (url.path() == "/https") { |
| 4919 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 4920 | return OK; |
| 4921 | } |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 4922 | if (url.path() == "/https_trusted") { |
| 4923 | results->UseProxyServer(ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 4924 | ProxyHostPortPair(), |
| 4925 | true /* is_trusted_proxy */)); |
| 4926 | return OK; |
| 4927 | } |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4928 | NOTREACHED(); |
| 4929 | return ERR_NOT_IMPLEMENTED; |
| 4930 | } |
| 4931 | |
| 4932 | private: |
| 4933 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 4934 | }; |
| 4935 | |
| 4936 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 4937 | : public ProxyResolverFactory { |
| 4938 | public: |
| 4939 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 4940 | : ProxyResolverFactory(false) {} |
| 4941 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4942 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 4943 | std::unique_ptr<ProxyResolver>* resolver, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4944 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4945 | std::unique_ptr<Request>* request) override { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4946 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 4947 | return OK; |
| 4948 | } |
| 4949 | |
| 4950 | private: |
| 4951 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 4952 | }; |
| 4953 | |
| 4954 | // 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] | 4955 | // same address, the connections are not grouped together. i.e., a request to |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4956 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 4957 | // request to foo.com using proxy.com as an HTTP proxy. |
| 4958 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4959 | session_deps_.proxy_resolution_service = |
| 4960 | std::make_unique<ProxyResolutionService>( |
| 4961 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 4962 | ProxyConfig::CreateAutoDetect(), TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 4963 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
| 4964 | nullptr); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4965 | |
| 4966 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4967 | |
| 4968 | MockWrite socks_writes[] = { |
| 4969 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 4970 | kSOCKS4OkRequestLocalHostPort80Length), |
| 4971 | MockWrite(SYNCHRONOUS, |
| 4972 | "GET /socks4 HTTP/1.1\r\n" |
| 4973 | "Host: test\r\n" |
| 4974 | "Connection: keep-alive\r\n\r\n"), |
| 4975 | }; |
| 4976 | MockRead socks_reads[] = { |
| 4977 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 4978 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4979 | "Connection: keep-alive\r\n" |
| 4980 | "Content-Length: 15\r\n\r\n" |
| 4981 | "SOCKS4 Response"), |
| 4982 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4983 | StaticSocketDataProvider socks_data(socks_reads, socks_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4984 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 4985 | |
| 4986 | const char kSOCKS5Request[] = { |
| 4987 | 0x05, // Version |
| 4988 | 0x01, // Command (CONNECT) |
| 4989 | 0x00, // Reserved |
| 4990 | 0x03, // Address type (DOMAINNAME) |
| 4991 | 0x04, // Length of domain (4) |
| 4992 | 't', 'e', 's', 't', // Domain string |
| 4993 | 0x00, 0x50, // 16-bit port (80) |
| 4994 | }; |
| 4995 | MockWrite socks5_writes[] = { |
| 4996 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 4997 | MockWrite(ASYNC, kSOCKS5Request, base::size(kSOCKS5Request)), |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4998 | MockWrite(SYNCHRONOUS, |
| 4999 | "GET /socks5 HTTP/1.1\r\n" |
| 5000 | "Host: test\r\n" |
| 5001 | "Connection: keep-alive\r\n\r\n"), |
| 5002 | }; |
| 5003 | MockRead socks5_reads[] = { |
| 5004 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 5005 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 5006 | MockRead("HTTP/1.0 200 OK\r\n" |
| 5007 | "Connection: keep-alive\r\n" |
| 5008 | "Content-Length: 15\r\n\r\n" |
| 5009 | "SOCKS5 Response"), |
| 5010 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5011 | StaticSocketDataProvider socks5_data(socks5_reads, socks5_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5012 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 5013 | |
| 5014 | MockWrite http_writes[] = { |
| 5015 | MockWrite(SYNCHRONOUS, |
| 5016 | "GET http://test/http HTTP/1.1\r\n" |
| 5017 | "Host: test\r\n" |
| 5018 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5019 | }; |
| 5020 | MockRead http_reads[] = { |
| 5021 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5022 | "Proxy-Connection: keep-alive\r\n" |
| 5023 | "Content-Length: 13\r\n\r\n" |
| 5024 | "HTTP Response"), |
| 5025 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5026 | StaticSocketDataProvider http_data(http_reads, http_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5027 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 5028 | |
| 5029 | MockWrite https_writes[] = { |
| 5030 | MockWrite(SYNCHRONOUS, |
| 5031 | "GET http://test/https HTTP/1.1\r\n" |
| 5032 | "Host: test\r\n" |
| 5033 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5034 | }; |
| 5035 | MockRead https_reads[] = { |
| 5036 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5037 | "Proxy-Connection: keep-alive\r\n" |
| 5038 | "Content-Length: 14\r\n\r\n" |
| 5039 | "HTTPS Response"), |
| 5040 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5041 | StaticSocketDataProvider https_data(https_reads, https_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5042 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 5043 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 5044 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5045 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5046 | MockWrite https_trusted_writes[] = { |
| 5047 | MockWrite(SYNCHRONOUS, |
| 5048 | "GET http://test/https_trusted HTTP/1.1\r\n" |
| 5049 | "Host: test\r\n" |
| 5050 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5051 | }; |
| 5052 | MockRead https_trusted_reads[] = { |
| 5053 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5054 | "Proxy-Connection: keep-alive\r\n" |
| 5055 | "Content-Length: 22\r\n\r\n" |
| 5056 | "HTTPS Trusted Response"), |
| 5057 | }; |
| 5058 | StaticSocketDataProvider trusted_https_data(https_trusted_reads, |
| 5059 | https_trusted_writes); |
| 5060 | session_deps_.socket_factory->AddSocketDataProvider(&trusted_https_data); |
| 5061 | SSLSocketDataProvider ssl2(SYNCHRONOUS, OK); |
| 5062 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 5063 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5064 | struct TestCase { |
| 5065 | GURL url; |
| 5066 | std::string expected_response; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5067 | // 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] | 5068 | // after the test. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5069 | int expected_idle_socks4_sockets; |
| 5070 | int expected_idle_socks5_sockets; |
| 5071 | // How many idle sockets there should be in the HTTP/HTTPS proxy socket |
| 5072 | // pools after the test. |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5073 | int expected_idle_http_sockets; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5074 | int expected_idle_https_sockets; |
| 5075 | // How many idle sockets there should be in the HTTPS proxy socket pool with |
| 5076 | // the ProxyServer's |is_trusted_proxy| bit set after the test. |
| 5077 | int expected_idle_trusted_https_sockets; |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5078 | } const kTestCases[] = { |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5079 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0, 0, 0, 0}, |
| 5080 | {GURL("http://test/socks5"), "SOCKS5 Response", 1, 1, 0, 0, 0}, |
| 5081 | {GURL("http://test/http"), "HTTP Response", 1, 1, 1, 0, 0}, |
| 5082 | {GURL("http://test/https"), "HTTPS Response", 1, 1, 1, 1, 0}, |
| 5083 | {GURL("http://test/https_trusted"), "HTTPS Trusted Response", 1, 1, 1, 1, |
| 5084 | 1}, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5085 | }; |
| 5086 | |
| 5087 | for (const auto& test_case : kTestCases) { |
| 5088 | HttpRequestInfo request; |
| 5089 | request.method = "GET"; |
| 5090 | request.url = test_case.url; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5091 | request.traffic_annotation = |
| 5092 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5093 | std::unique_ptr<HttpNetworkTransaction> trans = |
| 5094 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 5095 | session.get()); |
| 5096 | TestCompletionCallback callback; |
| 5097 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 5098 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5099 | |
| 5100 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5101 | ASSERT_TRUE(response); |
| 5102 | ASSERT_TRUE(response->headers); |
| 5103 | EXPECT_EQ(200, response->headers->response_code()); |
| 5104 | std::string response_data; |
| 5105 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 5106 | EXPECT_EQ(test_case.expected_response, response_data); |
| 5107 | |
| 5108 | // Return the socket to the socket pool, so can make sure it's not used for |
| 5109 | // the next requests. |
| 5110 | trans.reset(); |
| 5111 | base::RunLoop().RunUntilIdle(); |
| 5112 | |
| 5113 | // Check the number of idle sockets in the pool, to make sure that used |
| 5114 | // sockets are indeed being returned to the socket pool. If each request |
| 5115 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 5116 | // pass. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5117 | EXPECT_EQ(test_case.expected_idle_socks4_sockets, |
| 5118 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5119 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5120 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5121 | ProxyServer(ProxyServer::SCHEME_SOCKS4, |
| 5122 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5123 | ProxyHostPortPair())) |
| 5124 | ->IdleSocketCount()); |
| 5125 | EXPECT_EQ(test_case.expected_idle_socks5_sockets, |
| 5126 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5127 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5128 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5129 | ProxyServer(ProxyServer::SCHEME_SOCKS5, |
| 5130 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5131 | ProxyHostPortPair())) |
| 5132 | ->IdleSocketCount()); |
| 5133 | EXPECT_EQ(test_case.expected_idle_http_sockets, |
| 5134 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5135 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5136 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5137 | ProxyServer(ProxyServer::SCHEME_HTTP, |
| 5138 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5139 | ProxyHostPortPair())) |
| 5140 | ->IdleSocketCount()); |
| 5141 | EXPECT_EQ(test_case.expected_idle_https_sockets, |
| 5142 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5143 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5144 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5145 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5146 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5147 | ProxyHostPortPair())) |
| 5148 | ->IdleSocketCount()); |
| 5149 | EXPECT_EQ(test_case.expected_idle_trusted_https_sockets, |
| 5150 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5151 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5152 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5153 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5154 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5155 | ProxyHostPortPair(), |
| 5156 | true /* is_trusted_proxy */)) |
| 5157 | ->IdleSocketCount()); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5158 | } |
| 5159 | } |
| 5160 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5161 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5162 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5163 | HttpRequestInfo request1; |
| 5164 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5165 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5166 | request1.traffic_annotation = |
| 5167 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5168 | |
| 5169 | HttpRequestInfo request2; |
| 5170 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5171 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5172 | request2.traffic_annotation = |
| 5173 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5174 | |
| 5175 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5176 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5177 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5178 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5179 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5180 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5181 | |
| 5182 | // Since we have proxy, should try to establish tunnel. |
| 5183 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5184 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5185 | "Host: www.example.org:443\r\n" |
| 5186 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5187 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5188 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5189 | "Host: www.example.org\r\n" |
| 5190 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5191 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5192 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5193 | "Host: www.example.org\r\n" |
| 5194 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5195 | }; |
| 5196 | |
| 5197 | // The proxy responds to the connect with a 407, using a persistent |
| 5198 | // connection. |
| 5199 | MockRead data_reads1[] = { |
| 5200 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5201 | |
| 5202 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5203 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5204 | MockRead(SYNCHRONOUS, "1"), |
| 5205 | |
| 5206 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5207 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5208 | MockRead(SYNCHRONOUS, "22"), |
| 5209 | }; |
| 5210 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5211 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5212 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5213 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5214 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5215 | |
| 5216 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5217 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5218 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5219 | |
| 5220 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5221 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5222 | |
| 5223 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5224 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5225 | |
| 5226 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5227 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5228 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5229 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5230 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5231 | |
| 5232 | LoadTimingInfo load_timing_info1; |
| 5233 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5234 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5235 | |
| 5236 | trans1.reset(); |
| 5237 | |
| 5238 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5239 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5240 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5241 | |
| 5242 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5243 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5244 | |
| 5245 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5246 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5247 | |
| 5248 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5249 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5250 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5251 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5252 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5253 | |
| 5254 | LoadTimingInfo load_timing_info2; |
| 5255 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5256 | TestLoadTimingReused(load_timing_info2); |
| 5257 | |
| 5258 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5259 | |
| 5260 | trans2.reset(); |
| 5261 | session->CloseAllConnections(); |
| 5262 | } |
| 5263 | |
| 5264 | // 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] | 5265 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5266 | HttpRequestInfo request1; |
| 5267 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5268 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5269 | request1.traffic_annotation = |
| 5270 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5271 | |
| 5272 | HttpRequestInfo request2; |
| 5273 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5274 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5275 | request2.traffic_annotation = |
| 5276 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5277 | |
| 5278 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5279 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5280 | ProxyResolutionService::CreateFixedFromPacResult( |
| 5281 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5282 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5283 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5284 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5285 | |
| 5286 | // Since we have proxy, should try to establish tunnel. |
| 5287 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5288 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5289 | "Host: www.example.org:443\r\n" |
| 5290 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5291 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5292 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5293 | "Host: www.example.org\r\n" |
| 5294 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5295 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5296 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5297 | "Host: www.example.org\r\n" |
| 5298 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5299 | }; |
| 5300 | |
| 5301 | // The proxy responds to the connect with a 407, using a persistent |
| 5302 | // connection. |
| 5303 | MockRead data_reads1[] = { |
| 5304 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5305 | |
| 5306 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5307 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5308 | MockRead(SYNCHRONOUS, "1"), |
| 5309 | |
| 5310 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5311 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5312 | MockRead(SYNCHRONOUS, "22"), |
| 5313 | }; |
| 5314 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5315 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5316 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5317 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5318 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5319 | |
| 5320 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5321 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5322 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5323 | |
| 5324 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5325 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5326 | |
| 5327 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5328 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5329 | |
| 5330 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5331 | ASSERT_TRUE(response1); |
| 5332 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5333 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5334 | |
| 5335 | LoadTimingInfo load_timing_info1; |
| 5336 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5337 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 5338 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 5339 | |
| 5340 | trans1.reset(); |
| 5341 | |
| 5342 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5343 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5344 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5345 | |
| 5346 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5347 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5348 | |
| 5349 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5350 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5351 | |
| 5352 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5353 | ASSERT_TRUE(response2); |
| 5354 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5355 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5356 | |
| 5357 | LoadTimingInfo load_timing_info2; |
| 5358 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5359 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 5360 | |
| 5361 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5362 | |
| 5363 | trans2.reset(); |
| 5364 | session->CloseAllConnections(); |
| 5365 | } |
| 5366 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5367 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5368 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5369 | HttpRequestInfo request; |
| 5370 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5371 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5372 | request.traffic_annotation = |
| 5373 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5374 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5375 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5376 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5377 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5378 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5379 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5380 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5381 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5382 | // Since we have proxy, should use full url |
| 5383 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5384 | MockWrite( |
| 5385 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5386 | "Host: www.example.org\r\n" |
| 5387 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5388 | }; |
| 5389 | |
| 5390 | MockRead data_reads1[] = { |
| 5391 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5392 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5393 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5394 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5395 | }; |
| 5396 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5397 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5398 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5399 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5400 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5401 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5402 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5403 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5404 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5405 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5406 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5407 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5408 | |
| 5409 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5410 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5411 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5412 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5413 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5414 | TestLoadTimingNotReused(load_timing_info, |
| 5415 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5416 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5417 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5418 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5419 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5420 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5421 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5422 | EXPECT_EQ(200, response->headers->response_code()); |
| 5423 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5424 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5425 | |
| 5426 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5427 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5428 | } |
| 5429 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5430 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5431 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5432 | HttpRequestInfo request; |
| 5433 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5434 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5435 | request.traffic_annotation = |
| 5436 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5437 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5438 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5439 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5440 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5441 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5442 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5443 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5444 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5445 | // fetch http://www.example.org/ via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5446 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5447 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5448 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5449 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5450 | spdy::SpdySerializedFrame resp( |
| 5451 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 5452 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5453 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5454 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5455 | }; |
| 5456 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5457 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5458 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5459 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5460 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5461 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5462 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5463 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5464 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5465 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5466 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5467 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5468 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5469 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5470 | |
| 5471 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5472 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5473 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5474 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5475 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5476 | TestLoadTimingNotReused(load_timing_info, |
| 5477 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5478 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5479 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5480 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5481 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5482 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5483 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5484 | |
| 5485 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5486 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5487 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5488 | } |
| 5489 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5490 | // Verifies that a session which races and wins against the owning transaction |
| 5491 | // (completing prior to host resolution), doesn't fail the transaction. |
| 5492 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5493 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5494 | HttpRequestInfo request; |
| 5495 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5496 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5497 | request.traffic_annotation = |
| 5498 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5499 | |
| 5500 | // Configure SPDY proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5501 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5502 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5503 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5504 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5505 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5506 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5507 | // Fetch http://www.example.org/ through the SPDY proxy. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5508 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5509 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5510 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5511 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5512 | spdy::SpdySerializedFrame resp( |
| 5513 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5514 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5515 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5516 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5517 | }; |
| 5518 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5519 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5520 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5521 | |
| 5522 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5523 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5524 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5525 | |
| 5526 | TestCompletionCallback callback1; |
| 5527 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5528 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5529 | |
| 5530 | // Stall the hostname resolution begun by the transaction. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5531 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5532 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5533 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5534 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5535 | |
| 5536 | // Race a session to the proxy, which completes first. |
| 5537 | session_deps_.host_resolver->set_ondemand_mode(false); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 5538 | SpdySessionKey key(HostPortPair("proxy", 70), ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 5539 | PRIVACY_MODE_DISABLED, |
| 5540 | SpdySessionKey::IsProxySession::kTrue, SocketTag()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5541 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 5542 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5543 | |
| 5544 | // Unstall the resolution begun by the transaction. |
| 5545 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5546 | session_deps_.host_resolver->ResolveAllPending(); |
| 5547 | |
| 5548 | EXPECT_FALSE(callback1.have_result()); |
| 5549 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5550 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5551 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5552 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5553 | ASSERT_TRUE(response); |
| 5554 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5555 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5556 | |
| 5557 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5558 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5559 | EXPECT_EQ(kUploadData, response_data); |
| 5560 | } |
| 5561 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5562 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5563 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5564 | HttpRequestInfo request; |
| 5565 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5566 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5567 | request.traffic_annotation = |
| 5568 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5569 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5570 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5571 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5572 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5573 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5574 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5575 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5576 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5577 | // The first request will be a bare GET, the second request will be a |
| 5578 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5579 | spdy_util_.set_default_url(request.url); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5580 | spdy::SpdySerializedFrame req_get( |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5581 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5582 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5583 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5584 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5585 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5586 | spdy::SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5587 | kExtraAuthorizationHeaders, base::size(kExtraAuthorizationHeaders) / 2, 3, |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5588 | LOWEST)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5589 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5590 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5591 | }; |
| 5592 | |
| 5593 | // The first response is a 407 proxy authentication challenge, and the second |
| 5594 | // response will be a 200 response since the second request includes a valid |
| 5595 | // Authorization header. |
| 5596 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5597 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5598 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5599 | spdy::SpdySerializedFrame resp_authentication( |
| 5600 | spdy_util_.ConstructSpdyReplyError( |
| 5601 | "407", kExtraAuthenticationHeaders, |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5602 | base::size(kExtraAuthenticationHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5603 | spdy::SpdySerializedFrame body_authentication( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5604 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5605 | spdy::SpdySerializedFrame resp_data( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5606 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5607 | spdy::SpdySerializedFrame body_data( |
| 5608 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5609 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5610 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5611 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5612 | CreateMockRead(resp_data, 4), |
| 5613 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5614 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5615 | }; |
| 5616 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5617 | SequencedSocketData data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5618 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5619 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5620 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5621 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5622 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5623 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5624 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5625 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5626 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5627 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5628 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5629 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5630 | |
| 5631 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5632 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5633 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5634 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5635 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5636 | ASSERT_TRUE(response); |
| 5637 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5638 | EXPECT_EQ(407, response->headers->response_code()); |
| 5639 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5640 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5641 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5642 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5643 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5644 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5645 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5646 | |
| 5647 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5648 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5649 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5650 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5651 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5652 | ASSERT_TRUE(response_restart); |
| 5653 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5654 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5655 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5656 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5657 | } |
| 5658 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5659 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5660 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5661 | HttpRequestInfo request; |
| 5662 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5663 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5664 | request.traffic_annotation = |
| 5665 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5666 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5667 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5668 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5669 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5670 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5671 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5672 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5673 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5674 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5675 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5676 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5677 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5678 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5679 | HostPortPair("www.example.org", 443))); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5680 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5681 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5682 | const char get[] = |
| 5683 | "GET / HTTP/1.1\r\n" |
| 5684 | "Host: www.example.org\r\n" |
| 5685 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5686 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5687 | spdy_util_.ConstructSpdyDataFrame(1, get, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5688 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5689 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5690 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 5691 | "Content-Length: 10\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5692 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5693 | spdy_util_.ConstructSpdyDataFrame(1, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5694 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5695 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5696 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5697 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5698 | |
| 5699 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5700 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5701 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5702 | }; |
| 5703 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5704 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5705 | CreateMockRead(conn_resp, 1, ASYNC), |
| 5706 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 5707 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 5708 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5709 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5710 | }; |
| 5711 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5712 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5713 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5714 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5715 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5716 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5717 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5718 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5719 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5720 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5721 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5722 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5723 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5724 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5725 | |
| 5726 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5727 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5728 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5729 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5730 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5731 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5732 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5733 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5734 | ASSERT_TRUE(response); |
| 5735 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5736 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5737 | |
| 5738 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5739 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5740 | EXPECT_EQ("1234567890", response_data); |
| 5741 | } |
| 5742 | |
| 5743 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5744 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5745 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5746 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5747 | HttpRequestInfo request; |
| 5748 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5749 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5750 | request.traffic_annotation = |
| 5751 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5752 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5753 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5754 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5755 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5756 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5757 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5758 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5759 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5760 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5761 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5762 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5763 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5764 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5765 | HostPortPair("www.example.org", 443))); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5766 | // fetch https://www.example.org/ via SPDY |
| 5767 | const char kMyUrl[] = "https://www.example.org/"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5768 | spdy::SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5769 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5770 | spdy::SpdySerializedFrame wrapped_get( |
| 5771 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 5772 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5773 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5774 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5775 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5776 | spdy::SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5777 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5778 | spdy::SpdySerializedFrame body( |
| 5779 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5780 | spdy::SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5781 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5782 | spdy::SpdySerializedFrame window_update_get_resp( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5783 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5784 | spdy::SpdySerializedFrame window_update_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5785 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5786 | |
| 5787 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5788 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5789 | CreateMockWrite(window_update_get_resp, 6), |
| 5790 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5791 | }; |
| 5792 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5793 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5794 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5795 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5796 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5797 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5798 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5799 | }; |
| 5800 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5801 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5802 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5803 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5804 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5805 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5806 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5807 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5808 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5809 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5810 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5811 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5812 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5813 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5814 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5815 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5816 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5817 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5818 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5819 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5820 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5821 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5822 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5823 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5824 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5825 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5826 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5827 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5828 | ASSERT_TRUE(response); |
| 5829 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5830 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5831 | |
| 5832 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5833 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5834 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5835 | } |
| 5836 | |
| 5837 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5838 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5839 | HttpRequestInfo request; |
| 5840 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5841 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5842 | request.traffic_annotation = |
| 5843 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5844 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5845 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5846 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5847 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5848 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5849 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5850 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5851 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5852 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5853 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5854 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5855 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5856 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5857 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5858 | spdy::SpdySerializedFrame get( |
| 5859 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5860 | |
| 5861 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5862 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5863 | }; |
| 5864 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5865 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
| 5866 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5867 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5868 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5869 | }; |
| 5870 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5871 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5872 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5873 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5874 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5875 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5876 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5877 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5878 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5879 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5880 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5881 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5882 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5883 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5884 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5885 | |
| 5886 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5887 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5888 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5889 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5890 | } |
| 5891 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5892 | // Test the case where a proxied H2 session doesn't exist when an auth challenge |
| 5893 | // is observed, but does exist by the time auth credentials are provided. |
| 5894 | // Proxy-Connection: Close is used so that there's a second DNS lookup, which is |
| 5895 | // what causes the existing H2 session to be noticed and reused. |
| 5896 | TEST_F(HttpNetworkTransactionTest, ProxiedH2SessionAppearsDuringAuth) { |
| 5897 | ProxyConfig proxy_config; |
| 5898 | proxy_config.set_auto_detect(true); |
| 5899 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 5900 | |
| 5901 | CapturingProxyResolver capturing_proxy_resolver; |
| 5902 | capturing_proxy_resolver.set_proxy_server( |
| 5903 | ProxyServer(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 70))); |
| 5904 | session_deps_.proxy_resolution_service = |
| 5905 | std::make_unique<ProxyResolutionService>( |
| 5906 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 5907 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 5908 | std::make_unique<CapturingProxyResolverFactory>( |
| 5909 | &capturing_proxy_resolver), |
| 5910 | nullptr); |
| 5911 | |
| 5912 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 5913 | |
| 5914 | const char kMyUrl[] = "https://www.example.org/"; |
| 5915 | spdy::SpdySerializedFrame get(spdy_util_.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 5916 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5917 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5918 | spdy::SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 5919 | |
| 5920 | spdy_util_.UpdateWithStreamDestruction(1); |
| 5921 | spdy::SpdySerializedFrame get2( |
| 5922 | spdy_util_.ConstructSpdyGet(kMyUrl, 3, LOWEST)); |
| 5923 | spdy::SpdySerializedFrame get_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5924 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5925 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
| 5926 | |
| 5927 | MockWrite auth_challenge_writes[] = { |
| 5928 | MockWrite(ASYNC, 0, |
| 5929 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5930 | "Host: www.example.org:443\r\n" |
| 5931 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5932 | }; |
| 5933 | |
| 5934 | MockRead auth_challenge_reads[] = { |
| 5935 | MockRead(ASYNC, 1, |
| 5936 | "HTTP/1.1 407 Authentication Required\r\n" |
| 5937 | "Content-Length: 0\r\n" |
| 5938 | "Proxy-Connection: close\r\n" |
| 5939 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
| 5940 | }; |
| 5941 | |
| 5942 | MockWrite spdy_writes[] = { |
| 5943 | MockWrite(ASYNC, 0, |
| 5944 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5945 | "Host: www.example.org:443\r\n" |
| 5946 | "Proxy-Connection: keep-alive\r\n" |
| 5947 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5948 | CreateMockWrite(get, 2), |
| 5949 | CreateMockWrite(get2, 5), |
| 5950 | }; |
| 5951 | |
| 5952 | MockRead spdy_reads[] = { |
| 5953 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 5954 | CreateMockRead(get_resp, 3, ASYNC), |
| 5955 | CreateMockRead(body, 4, ASYNC), |
| 5956 | CreateMockRead(get_resp2, 6, ASYNC), |
| 5957 | CreateMockRead(body2, 7, ASYNC), |
| 5958 | |
| 5959 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8), |
| 5960 | }; |
| 5961 | |
| 5962 | SequencedSocketData auth_challenge1(auth_challenge_reads, |
| 5963 | auth_challenge_writes); |
| 5964 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge1); |
| 5965 | |
| 5966 | SequencedSocketData auth_challenge2(auth_challenge_reads, |
| 5967 | auth_challenge_writes); |
| 5968 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge2); |
| 5969 | |
| 5970 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
| 5971 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5972 | |
| 5973 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5974 | ssl.next_proto = kProtoHTTP2; |
| 5975 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5976 | |
| 5977 | TestCompletionCallback callback; |
| 5978 | std::string response_data; |
| 5979 | |
| 5980 | // Run first request until an auth challenge is observed. |
| 5981 | HttpRequestInfo request1; |
| 5982 | request1.method = "GET"; |
| 5983 | request1.url = GURL(kMyUrl); |
| 5984 | request1.traffic_annotation = |
| 5985 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5986 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 5987 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 5988 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5989 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 5990 | ASSERT_TRUE(response); |
| 5991 | ASSERT_TRUE(response->headers); |
| 5992 | EXPECT_EQ(407, response->headers->response_code()); |
| 5993 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5994 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 5995 | |
| 5996 | // Run second request until an auth challenge is observed. |
| 5997 | HttpRequestInfo request2; |
| 5998 | request2.method = "GET"; |
| 5999 | request2.url = GURL(kMyUrl); |
| 6000 | request2.traffic_annotation = |
| 6001 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6002 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6003 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 6004 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6005 | response = trans2.GetResponseInfo(); |
| 6006 | ASSERT_TRUE(response); |
| 6007 | ASSERT_TRUE(response->headers); |
| 6008 | EXPECT_EQ(407, response->headers->response_code()); |
| 6009 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6010 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 6011 | |
| 6012 | // Now provide credentials for the first request, and wait for it to complete. |
| 6013 | rv = trans1.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6014 | rv = callback.GetResult(rv); |
| 6015 | EXPECT_THAT(rv, IsOk()); |
| 6016 | response = trans1.GetResponseInfo(); |
| 6017 | ASSERT_TRUE(response); |
| 6018 | ASSERT_TRUE(response->headers); |
| 6019 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6020 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6021 | EXPECT_EQ(kUploadData, response_data); |
| 6022 | |
| 6023 | // Now provide credentials for the second request. It should notice the |
| 6024 | // existing session, and reuse it. |
| 6025 | rv = trans2.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6026 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6027 | response = trans2.GetResponseInfo(); |
| 6028 | ASSERT_TRUE(response); |
| 6029 | ASSERT_TRUE(response->headers); |
| 6030 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6031 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6032 | EXPECT_EQ(kUploadData, response_data); |
| 6033 | } |
| 6034 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6035 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6036 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6037 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6038 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 6039 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6040 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6041 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6042 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6043 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6044 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6045 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6046 | |
| 6047 | HttpRequestInfo request1; |
| 6048 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6049 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6050 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6051 | request1.traffic_annotation = |
| 6052 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6053 | |
| 6054 | HttpRequestInfo request2; |
| 6055 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6056 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6057 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6058 | request2.traffic_annotation = |
| 6059 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6060 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6061 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6062 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6063 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6064 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6065 | spdy::SpdySerializedFrame conn_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6066 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6067 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6068 | // Fetch https://www.example.org/ via HTTP. |
| 6069 | const char get1[] = |
| 6070 | "GET / HTTP/1.1\r\n" |
| 6071 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6072 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6073 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6074 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6075 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6076 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6077 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6078 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6079 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6080 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6081 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6082 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6083 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6084 | // CONNECT to mail.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6085 | spdy::SpdyHeaderBlock connect2_block; |
| 6086 | connect2_block[spdy::kHttp2MethodHeader] = "CONNECT"; |
| 6087 | connect2_block[spdy::kHttp2AuthorityHeader] = "mail.example.org:443"; |
| 6088 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6089 | 3, std::move(connect2_block), HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6090 | false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 6091 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6092 | spdy::SpdySerializedFrame conn_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6093 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6094 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6095 | // Fetch https://mail.example.org/ via HTTP. |
| 6096 | const char get2[] = |
| 6097 | "GET / HTTP/1.1\r\n" |
| 6098 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6099 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6100 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6101 | spdy_util_.ConstructSpdyDataFrame(3, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6102 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6103 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6104 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6105 | spdy_util_.ConstructSpdyDataFrame(3, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6106 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6107 | spdy_util_.ConstructSpdyDataFrame(3, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6108 | |
| 6109 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6110 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6111 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6112 | }; |
| 6113 | |
| 6114 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6115 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6116 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 6117 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 6118 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 6119 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 6120 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 6121 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6122 | }; |
| 6123 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6124 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6125 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6126 | |
| 6127 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6128 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6129 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6130 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6131 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6132 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6133 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6134 | |
| 6135 | TestCompletionCallback callback; |
| 6136 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6137 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6138 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6139 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6140 | |
| 6141 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6142 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6143 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6144 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6145 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6146 | ASSERT_TRUE(response); |
| 6147 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6148 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6149 | |
| 6150 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6151 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6152 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6153 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6154 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6155 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6156 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6157 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6158 | |
| 6159 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6160 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6161 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 6162 | // to be created, so the socket's load timing looks like a fresh connection. |
| 6163 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6164 | |
| 6165 | // The requests should have different IDs, since they each are using their own |
| 6166 | // separate stream. |
| 6167 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6168 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6169 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6170 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6171 | } |
| 6172 | |
| 6173 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6174 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6175 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6176 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 6177 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6178 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6179 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6180 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6181 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6182 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6183 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6184 | |
| 6185 | HttpRequestInfo request1; |
| 6186 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6187 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6188 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6189 | request1.traffic_annotation = |
| 6190 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6191 | |
| 6192 | HttpRequestInfo request2; |
| 6193 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6194 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6195 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6196 | request2.traffic_annotation = |
| 6197 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6198 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6199 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6200 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6201 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6202 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6203 | spdy::SpdySerializedFrame conn_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6204 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6205 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6206 | // Fetch https://www.example.org/ via HTTP. |
| 6207 | const char get1[] = |
| 6208 | "GET / HTTP/1.1\r\n" |
| 6209 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6210 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6211 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6212 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6213 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6214 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6215 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6216 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6217 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6218 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6219 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6220 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6221 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6222 | // Fetch https://www.example.org/2 via HTTP. |
| 6223 | const char get2[] = |
| 6224 | "GET /2 HTTP/1.1\r\n" |
| 6225 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6226 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6227 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6228 | spdy_util_.ConstructSpdyDataFrame(1, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6229 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6230 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6231 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6232 | spdy_util_.ConstructSpdyDataFrame(1, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6233 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6234 | spdy_util_.ConstructSpdyDataFrame(1, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6235 | |
| 6236 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6237 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6238 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6239 | }; |
| 6240 | |
| 6241 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6242 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6243 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6244 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6245 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6246 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6247 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6248 | }; |
| 6249 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6250 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6251 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6252 | |
| 6253 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6254 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6255 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6256 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6257 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6258 | |
| 6259 | TestCompletionCallback callback; |
| 6260 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6261 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6262 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6263 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6264 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6265 | |
| 6266 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6267 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6268 | |
| 6269 | LoadTimingInfo load_timing_info; |
| 6270 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6271 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6272 | |
| 6273 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6274 | ASSERT_TRUE(response); |
| 6275 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6276 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6277 | |
| 6278 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6279 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6280 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6281 | trans.reset(); |
| 6282 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6283 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6284 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6285 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6286 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6287 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6288 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6289 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6290 | |
| 6291 | LoadTimingInfo load_timing_info2; |
| 6292 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 6293 | TestLoadTimingReused(load_timing_info2); |
| 6294 | |
| 6295 | // The requests should have the same ID. |
| 6296 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6297 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6298 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6299 | } |
| 6300 | |
| 6301 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 6302 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6303 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6304 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6305 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6306 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6307 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6308 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6309 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6310 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6311 | |
| 6312 | HttpRequestInfo request1; |
| 6313 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6314 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6315 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6316 | request1.traffic_annotation = |
| 6317 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6318 | |
| 6319 | HttpRequestInfo request2; |
| 6320 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6321 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6322 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6323 | request2.traffic_annotation = |
| 6324 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6325 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6326 | // http://www.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6327 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6328 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6329 | spdy::SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6330 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6331 | spdy::SpdySerializedFrame get_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6332 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6333 | spdy::SpdySerializedFrame body1( |
| 6334 | spdy_util_.ConstructSpdyDataFrame(1, "1", true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 6335 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6336 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6337 | // http://mail.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6338 | spdy::SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6339 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6340 | spdy::SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6341 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6342 | spdy::SpdySerializedFrame get_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6343 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6344 | spdy::SpdySerializedFrame body2( |
| 6345 | spdy_util_.ConstructSpdyDataFrame(3, "22", true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6346 | |
| 6347 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6348 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6349 | }; |
| 6350 | |
| 6351 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6352 | CreateMockRead(get_resp1, 1, ASYNC), |
| 6353 | CreateMockRead(body1, 2, ASYNC), |
| 6354 | CreateMockRead(get_resp2, 4, ASYNC), |
| 6355 | CreateMockRead(body2, 5, ASYNC), |
| 6356 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6357 | }; |
| 6358 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6359 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6360 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6361 | |
| 6362 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6363 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6364 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6365 | |
| 6366 | TestCompletionCallback callback; |
| 6367 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6368 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6369 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6370 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6371 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6372 | |
| 6373 | LoadTimingInfo load_timing_info; |
| 6374 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6375 | TestLoadTimingNotReused(load_timing_info, |
| 6376 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6377 | |
| 6378 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6379 | ASSERT_TRUE(response); |
| 6380 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6381 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6382 | |
| 6383 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6384 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6385 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 6386 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6387 | // Delete the first request, so the second one can reuse the socket. |
| 6388 | trans.reset(); |
| 6389 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6390 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6391 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6392 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6393 | |
| 6394 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6395 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6396 | TestLoadTimingReused(load_timing_info2); |
| 6397 | |
| 6398 | // The requests should have the same ID. |
| 6399 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6400 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6401 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6402 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6403 | } |
| 6404 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6405 | // Test that an HTTP/2 CONNECT through an HTTPS Proxy to a HTTP/2 server and a |
| 6406 | // direct (non-proxied) request to the proxy server are not pooled, as that |
| 6407 | // would break socket pool isolation. |
| 6408 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation1) { |
| 6409 | ProxyConfig proxy_config; |
| 6410 | proxy_config.set_auto_detect(true); |
| 6411 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6412 | |
| 6413 | CapturingProxyResolver capturing_proxy_resolver; |
| 6414 | session_deps_.proxy_resolution_service = |
| 6415 | std::make_unique<ProxyResolutionService>( |
| 6416 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6417 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6418 | std::make_unique<CapturingProxyResolverFactory>( |
| 6419 | &capturing_proxy_resolver), |
| 6420 | nullptr); |
| 6421 | |
| 6422 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6423 | |
| 6424 | SpdyTestUtil spdy_util1; |
| 6425 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6426 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6427 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6428 | HostPortPair("www.example.org", 443))); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6429 | // fetch https://www.example.org/ via HTTP/2. |
| 6430 | const char kMyUrl[] = "https://www.example.org/"; |
| 6431 | spdy::SpdySerializedFrame get(spdy_util1.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6432 | spdy::SpdySerializedFrame wrapped_get( |
| 6433 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6434 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6435 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6436 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6437 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6438 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6439 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6440 | spdy::SpdySerializedFrame body(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6441 | spdy::SpdySerializedFrame wrapped_body( |
| 6442 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6443 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6444 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6445 | spdy::SpdySerializedFrame window_update_body( |
| 6446 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6447 | |
| 6448 | MockWrite spdy_writes1[] = { |
| 6449 | CreateMockWrite(connect, 0), |
| 6450 | CreateMockWrite(wrapped_get, 2), |
| 6451 | CreateMockWrite(window_update_get_resp, 6), |
| 6452 | CreateMockWrite(window_update_body, 7), |
| 6453 | }; |
| 6454 | |
| 6455 | MockRead spdy_reads1[] = { |
| 6456 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6457 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6458 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6459 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6460 | MockRead(ASYNC, 0, 8), |
| 6461 | }; |
| 6462 | |
| 6463 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6464 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6465 | |
| 6466 | // Fetch https://proxy:70/ via HTTP/2. Needs a new SpdyTestUtil, since it uses |
| 6467 | // a new pipe. |
| 6468 | SpdyTestUtil spdy_util2; |
| 6469 | spdy::SpdySerializedFrame req( |
| 6470 | spdy_util2.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6471 | MockWrite spdy_writes2[] = {CreateMockWrite(req, 0)}; |
| 6472 | |
| 6473 | spdy::SpdySerializedFrame resp( |
| 6474 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6475 | spdy::SpdySerializedFrame data(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6476 | MockRead spdy_reads2[] = { |
| 6477 | CreateMockRead(resp, 1), |
| 6478 | CreateMockRead(data, 2), |
| 6479 | MockRead(ASYNC, 0, 3), |
| 6480 | }; |
| 6481 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6482 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6483 | |
| 6484 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6485 | ssl.next_proto = kProtoHTTP2; |
| 6486 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6487 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6488 | ssl2.next_proto = kProtoHTTP2; |
| 6489 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6490 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6491 | ssl3.next_proto = kProtoHTTP2; |
| 6492 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6493 | |
| 6494 | TestCompletionCallback callback; |
| 6495 | std::string response_data; |
| 6496 | |
| 6497 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6498 | capturing_proxy_resolver.set_proxy_server( |
| 6499 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6500 | HttpRequestInfo request1; |
| 6501 | request1.method = "GET"; |
| 6502 | request1.url = GURL("https://www.example.org/"); |
| 6503 | request1.traffic_annotation = |
| 6504 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6505 | |
| 6506 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6507 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 6508 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6509 | |
| 6510 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6511 | base::RunLoop().RunUntilIdle(); |
| 6512 | // Now allow the read of the response to complete. |
| 6513 | spdy_data1.Resume(); |
| 6514 | rv = callback.WaitForResult(); |
| 6515 | EXPECT_THAT(rv, IsOk()); |
| 6516 | |
| 6517 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 6518 | ASSERT_TRUE(response); |
| 6519 | ASSERT_TRUE(response->headers); |
| 6520 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6521 | |
| 6522 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6523 | EXPECT_EQ(kUploadData, response_data); |
| 6524 | RunUntilIdle(); |
| 6525 | |
| 6526 | // Make a direct HTTP/2 request to proxy:70. |
| 6527 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6528 | HttpRequestInfo request2; |
| 6529 | request2.method = "GET"; |
| 6530 | request2.url = GURL("https://proxy:70/"); |
| 6531 | request2.traffic_annotation = |
| 6532 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6533 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6534 | EXPECT_THAT(callback.GetResult(trans2.Start(&request2, callback.callback(), |
| 6535 | NetLogWithSource())), |
| 6536 | IsOk()); |
| 6537 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6538 | } |
| 6539 | |
| 6540 | // Same as above, but reverse request order, since the code to check for an |
| 6541 | // existing session is different for tunnels and direct connections. |
| 6542 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation2) { |
| 6543 | // Configure against https proxy server "myproxy:80". |
| 6544 | ProxyConfig proxy_config; |
| 6545 | proxy_config.set_auto_detect(true); |
| 6546 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6547 | |
| 6548 | CapturingProxyResolver capturing_proxy_resolver; |
| 6549 | session_deps_.proxy_resolution_service = |
| 6550 | std::make_unique<ProxyResolutionService>( |
| 6551 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6552 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6553 | std::make_unique<CapturingProxyResolverFactory>( |
| 6554 | &capturing_proxy_resolver), |
| 6555 | nullptr); |
| 6556 | |
| 6557 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6558 | // Fetch https://proxy:70/ via HTTP/2. |
| 6559 | SpdyTestUtil spdy_util1; |
| 6560 | spdy::SpdySerializedFrame req( |
| 6561 | spdy_util1.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6562 | MockWrite spdy_writes1[] = {CreateMockWrite(req, 0)}; |
| 6563 | |
| 6564 | spdy::SpdySerializedFrame resp( |
| 6565 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6566 | spdy::SpdySerializedFrame data(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6567 | MockRead spdy_reads1[] = { |
| 6568 | CreateMockRead(resp, 1), |
| 6569 | CreateMockRead(data, 2), |
| 6570 | MockRead(ASYNC, 0, 3), |
| 6571 | }; |
| 6572 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6573 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6574 | |
| 6575 | SpdyTestUtil spdy_util2; |
| 6576 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6577 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6578 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6579 | HostPortPair("www.example.org", 443))); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6580 | // fetch https://www.example.org/ via HTTP/2. |
| 6581 | const char kMyUrl[] = "https://www.example.org/"; |
| 6582 | spdy::SpdySerializedFrame get(spdy_util2.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6583 | spdy::SpdySerializedFrame wrapped_get( |
| 6584 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6585 | spdy::SpdySerializedFrame conn_resp( |
| 6586 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6587 | spdy::SpdySerializedFrame get_resp( |
| 6588 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6589 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6590 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6591 | spdy::SpdySerializedFrame body(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6592 | spdy::SpdySerializedFrame wrapped_body( |
| 6593 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6594 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6595 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6596 | spdy::SpdySerializedFrame window_update_body( |
| 6597 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6598 | |
| 6599 | MockWrite spdy_writes2[] = { |
| 6600 | CreateMockWrite(connect, 0), |
| 6601 | CreateMockWrite(wrapped_get, 2), |
| 6602 | CreateMockWrite(window_update_get_resp, 6), |
| 6603 | CreateMockWrite(window_update_body, 7), |
| 6604 | }; |
| 6605 | |
| 6606 | MockRead spdy_reads2[] = { |
| 6607 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6608 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6609 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6610 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6611 | MockRead(ASYNC, 0, 8), |
| 6612 | }; |
| 6613 | |
| 6614 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6615 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6616 | |
| 6617 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6618 | ssl.next_proto = kProtoHTTP2; |
| 6619 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6620 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6621 | ssl2.next_proto = kProtoHTTP2; |
| 6622 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6623 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6624 | ssl3.next_proto = kProtoHTTP2; |
| 6625 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6626 | |
| 6627 | TestCompletionCallback callback; |
| 6628 | std::string response_data; |
| 6629 | |
| 6630 | // Make a direct HTTP/2 request to proxy:70. |
| 6631 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6632 | HttpRequestInfo request1; |
| 6633 | request1.method = "GET"; |
| 6634 | request1.url = GURL("https://proxy:70/"); |
| 6635 | request1.traffic_annotation = |
| 6636 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6637 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6638 | EXPECT_THAT(callback.GetResult(trans1.Start(&request1, callback.callback(), |
| 6639 | NetLogWithSource())), |
| 6640 | IsOk()); |
| 6641 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6642 | RunUntilIdle(); |
| 6643 | |
| 6644 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6645 | capturing_proxy_resolver.set_proxy_server( |
| 6646 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6647 | HttpRequestInfo request2; |
| 6648 | request2.method = "GET"; |
| 6649 | request2.url = GURL("https://www.example.org/"); |
| 6650 | request2.traffic_annotation = |
| 6651 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6652 | |
| 6653 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6654 | int rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 6655 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6656 | |
| 6657 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6658 | base::RunLoop().RunUntilIdle(); |
| 6659 | // Now allow the read of the response to complete. |
| 6660 | spdy_data2.Resume(); |
| 6661 | rv = callback.WaitForResult(); |
| 6662 | EXPECT_THAT(rv, IsOk()); |
| 6663 | |
| 6664 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 6665 | ASSERT_TRUE(response2); |
| 6666 | ASSERT_TRUE(response2->headers); |
| 6667 | EXPECT_EQ("HTTP/1.1 200", response2->headers->GetStatusLine()); |
| 6668 | |
| 6669 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6670 | EXPECT_EQ(kUploadData, response_data); |
| 6671 | } |
| 6672 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6673 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6674 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6675 | HttpRequestInfo request; |
| 6676 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6677 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6678 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 6679 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6680 | request.traffic_annotation = |
| 6681 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6682 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6683 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6684 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6685 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6686 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6687 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6688 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6689 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6690 | // Since we have proxy, should use full url |
| 6691 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6692 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6693 | "Host: www.example.org\r\n" |
| 6694 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6695 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6696 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6697 | // be issuing -- the final header line contains the credentials. |
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" |
| 6701 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6702 | }; |
| 6703 | |
| 6704 | // The proxy responds to the GET with a 407, using a persistent |
| 6705 | // connection. |
| 6706 | MockRead data_reads1[] = { |
| 6707 | // No credentials. |
| 6708 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 6709 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6710 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 6711 | MockRead("Content-Length: 0\r\n\r\n"), |
| 6712 | |
| 6713 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6714 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6715 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6716 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6717 | }; |
| 6718 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6719 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6720 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6721 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6722 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6723 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6724 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6725 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6726 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6727 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6728 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6729 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6730 | |
| 6731 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6732 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6733 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6734 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6735 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6736 | TestLoadTimingNotReused(load_timing_info, |
| 6737 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6738 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6739 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6740 | ASSERT_TRUE(response); |
| 6741 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6742 | EXPECT_EQ(407, response->headers->response_code()); |
| 6743 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 6744 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame^] | 6745 | EXPECT_FALSE(response->did_use_http_auth); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6746 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6747 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6748 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6749 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6750 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6751 | |
| 6752 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6753 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6754 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6755 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6756 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6757 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 6758 | TestLoadTimingReused(load_timing_info); |
| 6759 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6760 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6761 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6762 | |
| 6763 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6764 | EXPECT_EQ(200, response->headers->response_code()); |
| 6765 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6766 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame^] | 6767 | EXPECT_TRUE(response->did_use_http_auth); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6768 | |
| 6769 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6770 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6771 | } |
| 6772 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6773 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6774 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6775 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6776 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6777 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6778 | request.traffic_annotation = |
| 6779 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6780 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6781 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6782 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6783 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6784 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6785 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6786 | // Since we have proxy, should try to establish tunnel. |
| 6787 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6788 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6789 | "Host: www.example.org:443\r\n" |
| 6790 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6791 | }; |
| 6792 | |
| 6793 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6794 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 6795 | // No response body because the test stops reading here. |
| 6796 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6797 | }; |
| 6798 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6799 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6800 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6801 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6802 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6803 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6804 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6805 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6806 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6807 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6808 | |
| 6809 | rv = callback.WaitForResult(); |
| 6810 | EXPECT_EQ(expected_status, rv); |
| 6811 | } |
| 6812 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6813 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 6814 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6815 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6816 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6817 | } |
| 6818 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6819 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6820 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 6821 | } |
| 6822 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6823 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6824 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 6825 | } |
| 6826 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6827 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6828 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 6829 | } |
| 6830 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6831 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6832 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 6833 | } |
| 6834 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6835 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6836 | ConnectStatusHelper( |
| 6837 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 6838 | } |
| 6839 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6840 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6841 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 6842 | } |
| 6843 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6844 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6845 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 6846 | } |
| 6847 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6848 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6849 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 6850 | } |
| 6851 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6852 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6853 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 6854 | } |
| 6855 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6856 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6857 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 6858 | } |
| 6859 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6860 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6861 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 6862 | } |
| 6863 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6864 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6865 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 6866 | } |
| 6867 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6868 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6869 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 6870 | } |
| 6871 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6872 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6873 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 6874 | } |
| 6875 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6876 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6877 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 6878 | } |
| 6879 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6880 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6881 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 6882 | } |
| 6883 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6884 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 6885 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 6886 | } |
| 6887 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6888 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6889 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 6890 | } |
| 6891 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6892 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6893 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 6894 | } |
| 6895 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6896 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6897 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 6898 | } |
| 6899 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6900 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6901 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 6902 | } |
| 6903 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6904 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6905 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 6906 | } |
| 6907 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6908 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6909 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 6910 | } |
| 6911 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6912 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6913 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 6914 | } |
| 6915 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6916 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6917 | ConnectStatusHelperWithExpectedStatus( |
| 6918 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 6919 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6920 | } |
| 6921 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6922 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6923 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 6924 | } |
| 6925 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6926 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6927 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 6928 | } |
| 6929 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6930 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6931 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 6932 | } |
| 6933 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6934 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6935 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 6936 | } |
| 6937 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6938 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6939 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 6940 | } |
| 6941 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6942 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6943 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 6944 | } |
| 6945 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6946 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6947 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 6948 | } |
| 6949 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6950 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6951 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 6952 | } |
| 6953 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6954 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6955 | ConnectStatusHelper( |
| 6956 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 6957 | } |
| 6958 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6959 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6960 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 6961 | } |
| 6962 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6963 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6964 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 6965 | } |
| 6966 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6967 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6968 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 6969 | } |
| 6970 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6971 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6972 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 6973 | } |
| 6974 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6975 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6976 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 6977 | } |
| 6978 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6979 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6980 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 6981 | } |
| 6982 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6983 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6984 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 6985 | } |
| 6986 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6987 | // Test the flow when both the proxy server AND origin server require |
| 6988 | // authentication. Again, this uses basic auth for both since that is |
| 6989 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6990 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6991 | HttpRequestInfo request; |
| 6992 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6993 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6994 | request.traffic_annotation = |
| 6995 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6996 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6997 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6998 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6999 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7000 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7001 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7002 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7003 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7004 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7005 | MockWrite( |
| 7006 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7007 | "Host: www.example.org\r\n" |
| 7008 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7009 | }; |
| 7010 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7011 | MockRead data_reads1[] = { |
| 7012 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 7013 | // Give a couple authenticate options (only the middle one is actually |
| 7014 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 7015 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7016 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7017 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 7018 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7019 | // Large content-length -- won't matter, as connection will be reset. |
| 7020 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7021 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7022 | }; |
| 7023 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7024 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7025 | // request we should be issuing -- the final header line contains the |
| 7026 | // proxy's credentials. |
| 7027 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7028 | MockWrite( |
| 7029 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7030 | "Host: www.example.org\r\n" |
| 7031 | "Proxy-Connection: keep-alive\r\n" |
| 7032 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7033 | }; |
| 7034 | |
| 7035 | // Now the proxy server lets the request pass through to origin server. |
| 7036 | // The origin server responds with a 401. |
| 7037 | MockRead data_reads2[] = { |
| 7038 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7039 | // Note: We are using the same realm-name as the proxy server. This is |
| 7040 | // completely valid, as realms are unique across hosts. |
| 7041 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7042 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7043 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7044 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7045 | }; |
| 7046 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7047 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7048 | // the credentials for both the proxy and origin server. |
| 7049 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7050 | MockWrite( |
| 7051 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7052 | "Host: www.example.org\r\n" |
| 7053 | "Proxy-Connection: keep-alive\r\n" |
| 7054 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 7055 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7056 | }; |
| 7057 | |
| 7058 | // Lastly we get the desired content. |
| 7059 | MockRead data_reads3[] = { |
| 7060 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7061 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7062 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7063 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7064 | }; |
| 7065 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7066 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7067 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7068 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7069 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7070 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7071 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7072 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7073 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7074 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7075 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7076 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7077 | |
| 7078 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7079 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7080 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7081 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7082 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7083 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7084 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7085 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7086 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7087 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7088 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7089 | |
| 7090 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7091 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7092 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7093 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7094 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7095 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7096 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7097 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7098 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7099 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7100 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7101 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7102 | |
| 7103 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7104 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7105 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7106 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7107 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7108 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7109 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7110 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7111 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 7112 | // can't hook into its internals to cause it to generate predictable NTLM |
| 7113 | // authorization headers. |
| 7114 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7115 | // The NTLM authentication unit tests are based on known test data from the |
| 7116 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 7117 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 7118 | // for the implementation and testing of the protocol. |
| 7119 | // |
| 7120 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7121 | |
| 7122 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7123 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7124 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7125 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7126 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7127 | request.traffic_annotation = |
| 7128 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7129 | |
| 7130 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7131 | // to other auth schemes. |
| 7132 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7133 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7134 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7135 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7136 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7137 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7138 | // Generate the NTLM messages based on known test data. |
| 7139 | std::string negotiate_msg; |
| 7140 | std::string challenge_msg; |
| 7141 | std::string authenticate_msg; |
| 7142 | base::Base64Encode( |
| 7143 | base::StringPiece( |
| 7144 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7145 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7146 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7147 | base::Base64Encode( |
| 7148 | base::StringPiece( |
| 7149 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7150 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7151 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7152 | base::Base64Encode( |
| 7153 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7154 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7155 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7156 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7157 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7158 | &authenticate_msg); |
| 7159 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7160 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7161 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7162 | "Host: server\r\n" |
| 7163 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7164 | }; |
| 7165 | |
| 7166 | MockRead data_reads1[] = { |
| 7167 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7168 | // Negotiate and NTLM are often requested together. However, we only want |
| 7169 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7170 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7171 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7172 | MockRead("Connection: close\r\n"), |
| 7173 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7174 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7175 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7176 | }; |
| 7177 | |
| 7178 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7179 | // After restarting with a null identity, this is the |
| 7180 | // request we should be issuing -- the final header line contains a Type |
| 7181 | // 1 message. |
| 7182 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7183 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7184 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7185 | "Authorization: NTLM "), |
| 7186 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7187 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7188 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7189 | // (using correct credentials). The second request continues on the |
| 7190 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7191 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7192 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7193 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7194 | "Authorization: NTLM "), |
| 7195 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7196 | }; |
| 7197 | |
| 7198 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7199 | // The origin server responds with a Type 2 message. |
| 7200 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7201 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7202 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7203 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7204 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7205 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7206 | // Lastly we get the desired content. |
| 7207 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7208 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7209 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7210 | }; |
| 7211 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7212 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7213 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7214 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7215 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7216 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7217 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7218 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7219 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7220 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7221 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7222 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7223 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7224 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7225 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7226 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7227 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7228 | |
| 7229 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7230 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7231 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7232 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7233 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7234 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7235 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7236 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7237 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7238 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7239 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7240 | rv = trans.RestartWithAuth( |
| 7241 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7242 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7243 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7244 | |
| 7245 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7246 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7247 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7248 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7249 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7250 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7251 | ASSERT_TRUE(response); |
| 7252 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7253 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7254 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7255 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7256 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7257 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7258 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7259 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7260 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7261 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7262 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7263 | ASSERT_TRUE(response); |
| 7264 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7265 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7266 | |
| 7267 | std::string response_data; |
| 7268 | rv = ReadTransaction(&trans, &response_data); |
| 7269 | EXPECT_THAT(rv, IsOk()); |
| 7270 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7271 | |
| 7272 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7273 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7274 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7275 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7276 | } |
| 7277 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7278 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7279 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7280 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7281 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7282 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7283 | request.traffic_annotation = |
| 7284 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7285 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7286 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7287 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7288 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7289 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7290 | // Generate the NTLM messages based on known test data. |
| 7291 | std::string negotiate_msg; |
| 7292 | std::string challenge_msg; |
| 7293 | std::string authenticate_msg; |
| 7294 | base::Base64Encode( |
| 7295 | base::StringPiece( |
| 7296 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7297 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7298 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7299 | base::Base64Encode( |
| 7300 | base::StringPiece( |
| 7301 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7302 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7303 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7304 | base::Base64Encode( |
| 7305 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7306 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7307 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7308 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7309 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7310 | &authenticate_msg); |
| 7311 | |
| 7312 | // The authenticate message when |kWrongPassword| is sent. |
| 7313 | std::string wrong_password_authenticate_msg( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7314 | "TlRMTVNTUAADAAAAGAAYAFgAAACKAIoAcAAAAAwADAD6AAAACAAIAAYBAAAQABAADgEAAAAA" |
| 7315 | "AABYAAAAA4IIAAAAAAAAAAAAAPknEYqtJQtusopDRSfYzAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 7316 | "AAAAAOtVz38osnFdRRggUQHUJ3EBAQAAAAAAAIALyP0A1NIBqqqqqqqqqqoAAAAAAgAMAEQA" |
| 7317 | "bwBtAGEAaQBuAAEADABTAGUAcgB2AGUAcgAGAAQAAgAAAAoAEAAAAAAAAAAAAAAAAAAAAAAA" |
| 7318 | "CQAWAEgAVABUAFAALwBzAGUAcgB2AGUAcgAAAAAAAAAAAEQAbwBtAGEAaQBuAFUAcwBlAHIA" |
| 7319 | "QwBPAE0AUABVAFQARQBSAA=="); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7320 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7321 | // Sanity check that it's the same length as the correct authenticate message |
| 7322 | // and that it's different. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7323 | ASSERT_EQ(authenticate_msg.length(), |
| 7324 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7325 | ASSERT_NE(authenticate_msg, wrong_password_authenticate_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7326 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7327 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7328 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7329 | "Host: server\r\n" |
| 7330 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7331 | }; |
| 7332 | |
| 7333 | MockRead data_reads1[] = { |
| 7334 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7335 | // Negotiate and NTLM are often requested together. However, we only want |
| 7336 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7337 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7338 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7339 | MockRead("Connection: close\r\n"), |
| 7340 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7341 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7342 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7343 | }; |
| 7344 | |
| 7345 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7346 | // After restarting with a null identity, this is the |
| 7347 | // request we should be issuing -- the final header line contains a Type |
| 7348 | // 1 message. |
| 7349 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7350 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7351 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7352 | "Authorization: NTLM "), |
| 7353 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7354 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7355 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7356 | // (using incorrect credentials). The second request continues on the |
| 7357 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7358 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7359 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7360 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7361 | "Authorization: NTLM "), |
| 7362 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7363 | }; |
| 7364 | |
| 7365 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7366 | // The origin server responds with a Type 2 message. |
| 7367 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7368 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7369 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 7370 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7371 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7372 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7373 | // Wrong password. |
| 7374 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7375 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 7376 | MockRead("Content-Length: 42\r\n"), |
| 7377 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7378 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7379 | }; |
| 7380 | |
| 7381 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7382 | // After restarting with a null identity, this is the |
| 7383 | // request we should be issuing -- the final header line contains a Type |
| 7384 | // 1 message. |
| 7385 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7386 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7387 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7388 | "Authorization: NTLM "), |
| 7389 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7390 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7391 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7392 | // (the credentials for the origin server). The second request continues |
| 7393 | // on the same connection. |
| 7394 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7395 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7396 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7397 | "Authorization: NTLM "), |
| 7398 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7399 | }; |
| 7400 | |
| 7401 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7402 | // The origin server responds with a Type 2 message. |
| 7403 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7404 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7405 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7406 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7407 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7408 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7409 | // Lastly we get the desired content. |
| 7410 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7411 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7412 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7413 | }; |
| 7414 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7415 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7416 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7417 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7418 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7419 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7420 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7421 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7422 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7423 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7424 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7425 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7426 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 7427 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 7428 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7429 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7430 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7431 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7432 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7433 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7434 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7435 | |
| 7436 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7437 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7438 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7439 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7440 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7441 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7442 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7443 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7444 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7445 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7446 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7447 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7448 | rv = trans.RestartWithAuth( |
| 7449 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 7450 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7451 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7452 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7453 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7454 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7455 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7456 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7457 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7458 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7459 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7460 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7461 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7462 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7463 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7464 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7465 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7466 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7467 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7468 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7469 | |
| 7470 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7471 | rv = trans.RestartWithAuth( |
| 7472 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7473 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7474 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7475 | |
| 7476 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7477 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7478 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7479 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7480 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7481 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7482 | |
| 7483 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7484 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7485 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7486 | |
| 7487 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7488 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7489 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7490 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7491 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7492 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7493 | |
| 7494 | std::string response_data; |
| 7495 | rv = ReadTransaction(&trans, &response_data); |
| 7496 | EXPECT_THAT(rv, IsOk()); |
| 7497 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7498 | |
| 7499 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7500 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7501 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7502 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 7503 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 7504 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7505 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7506 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7507 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 7508 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7509 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7510 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7511 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7512 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7513 | const char* kUrl = "https://server/kids/login.aspx"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7514 | |
| 7515 | HttpRequestInfo request; |
| 7516 | request.method = "GET"; |
| 7517 | request.url = GURL(kUrl); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7518 | request.traffic_annotation = |
| 7519 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7520 | |
| 7521 | // First request without credentials. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7522 | spdy::SpdyHeaderBlock request_headers0( |
| 7523 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 7524 | spdy::SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7525 | 1, std::move(request_headers0), LOWEST, true)); |
| 7526 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7527 | spdy::SpdyHeaderBlock response_headers0; |
| 7528 | response_headers0[spdy::kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7529 | response_headers0["www-authenticate"] = "NTLM"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7530 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7531 | 1, std::move(response_headers0), true)); |
| 7532 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7533 | // Stream 1 is closed. |
| 7534 | spdy_util_.UpdateWithStreamDestruction(1); |
| 7535 | |
| 7536 | // Generate the NTLM messages based on known test data. |
| 7537 | std::string negotiate_msg; |
| 7538 | std::string challenge_msg; |
| 7539 | std::string authenticate_msg; |
| 7540 | base::Base64Encode( |
| 7541 | base::StringPiece( |
| 7542 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7543 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7544 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7545 | base::Base64Encode( |
| 7546 | base::StringPiece( |
| 7547 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7548 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7549 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7550 | base::Base64Encode( |
| 7551 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7552 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7553 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7554 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7555 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7556 | &authenticate_msg); |
| 7557 | |
| 7558 | // Retry with authorization header. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7559 | spdy::SpdyHeaderBlock request_headers1( |
| 7560 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7561 | request_headers1["authorization"] = std::string("NTLM ") + negotiate_msg; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7562 | spdy::SpdySerializedFrame request1(spdy_util_.ConstructSpdyHeaders( |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7563 | 3, std::move(request_headers1), LOWEST, true)); |
| 7564 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7565 | spdy::SpdySerializedFrame rst( |
| 7566 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_HTTP_1_1_REQUIRED)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7567 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7568 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
| 7569 | MockRead reads0[] = {CreateMockRead(resp, 1), MockRead(ASYNC, 0, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7570 | |
| 7571 | // Retry yet again using HTTP/1.1. |
| 7572 | MockWrite writes1[] = { |
| 7573 | // After restarting with a null identity, this is the |
| 7574 | // request we should be issuing -- the final header line contains a Type |
| 7575 | // 1 message. |
| 7576 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7577 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7578 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7579 | "Authorization: NTLM "), |
| 7580 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7581 | |
| 7582 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7583 | // (the credentials for the origin server). The second request continues |
| 7584 | // on the same connection. |
| 7585 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7586 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7587 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7588 | "Authorization: NTLM "), |
| 7589 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7590 | }; |
| 7591 | |
| 7592 | MockRead reads1[] = { |
| 7593 | // The origin server responds with a Type 2 message. |
| 7594 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7595 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7596 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7597 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7598 | MockRead("You are not authorized to view this page\r\n"), |
| 7599 | |
| 7600 | // Lastly we get the desired content. |
| 7601 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7602 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7603 | 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] | 7604 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7605 | SequencedSocketData data0(reads0, writes0); |
| 7606 | StaticSocketDataProvider data1(reads1, writes1); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7607 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 7608 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7609 | |
| 7610 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 7611 | ssl0.next_proto = kProtoHTTP2; |
| 7612 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7613 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 7614 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7615 | |
| 7616 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7617 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7618 | |
| 7619 | TestCompletionCallback callback1; |
| 7620 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 7621 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7622 | |
| 7623 | rv = callback1.WaitForResult(); |
| 7624 | EXPECT_THAT(rv, IsOk()); |
| 7625 | |
| 7626 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7627 | |
| 7628 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7629 | ASSERT_TRUE(response); |
| 7630 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
| 7631 | |
| 7632 | TestCompletionCallback callback2; |
| 7633 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7634 | rv = trans.RestartWithAuth( |
| 7635 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7636 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7637 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7638 | |
| 7639 | rv = callback2.WaitForResult(); |
| 7640 | EXPECT_THAT(rv, IsOk()); |
| 7641 | |
| 7642 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7643 | |
| 7644 | response = trans.GetResponseInfo(); |
| 7645 | ASSERT_TRUE(response); |
| 7646 | EXPECT_FALSE(response->auth_challenge); |
| 7647 | |
| 7648 | TestCompletionCallback callback3; |
| 7649 | |
| 7650 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 7651 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7652 | |
| 7653 | rv = callback3.WaitForResult(); |
| 7654 | EXPECT_THAT(rv, IsOk()); |
| 7655 | |
| 7656 | response = trans.GetResponseInfo(); |
| 7657 | ASSERT_TRUE(response); |
| 7658 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7659 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7660 | |
| 7661 | std::string response_data; |
| 7662 | rv = ReadTransaction(&trans, &response_data); |
| 7663 | EXPECT_THAT(rv, IsOk()); |
| 7664 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7665 | |
| 7666 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 7667 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 7668 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7669 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7670 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7671 | |
| 7672 | // Test that, if we have an NTLM proxy and the origin resets the connection, we |
| 7673 | // do no retry forever checking for TLS version interference. This is a |
| 7674 | // regression test for https://crbug.com/823387. |
| 7675 | TEST_F(HttpNetworkTransactionTest, NTLMProxyTLSHandshakeReset) { |
| 7676 | // The NTLM test data expects the proxy to be named 'server'. The origin is |
| 7677 | // https://origin/. |
| 7678 | session_deps_.proxy_resolution_service = |
| 7679 | ProxyResolutionService::CreateFixedFromPacResult( |
| 7680 | "PROXY server", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7681 | |
| 7682 | SSLConfig config; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7683 | session_deps_.ssl_config_service = |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 7684 | std::make_unique<TestSSLConfigService>(config); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7685 | |
| 7686 | HttpRequestInfo request; |
| 7687 | request.method = "GET"; |
| 7688 | request.url = GURL("https://origin/"); |
| 7689 | request.traffic_annotation = |
| 7690 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7691 | |
| 7692 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7693 | // to other auth schemes. |
| 7694 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 7695 | |
| 7696 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7697 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
| 7698 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7699 | |
| 7700 | // Generate the NTLM messages based on known test data. |
| 7701 | std::string negotiate_msg; |
| 7702 | std::string challenge_msg; |
| 7703 | std::string authenticate_msg; |
| 7704 | base::Base64Encode( |
| 7705 | base::StringPiece( |
| 7706 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7707 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7708 | &negotiate_msg); |
| 7709 | base::Base64Encode( |
| 7710 | base::StringPiece( |
| 7711 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7712 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7713 | &challenge_msg); |
| 7714 | base::Base64Encode( |
| 7715 | base::StringPiece( |
| 7716 | reinterpret_cast<const char*>( |
| 7717 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7718 | base::size( |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7719 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
| 7720 | &authenticate_msg); |
| 7721 | |
| 7722 | MockWrite data_writes[] = { |
| 7723 | // The initial CONNECT request. |
| 7724 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7725 | "Host: origin:443\r\n" |
| 7726 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7727 | |
| 7728 | // After restarting with an identity. |
| 7729 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7730 | "Host: origin:443\r\n" |
| 7731 | "Proxy-Connection: keep-alive\r\n" |
| 7732 | "Proxy-Authorization: NTLM "), |
| 7733 | MockWrite(negotiate_msg.c_str()), |
| 7734 | // End headers. |
| 7735 | MockWrite("\r\n\r\n"), |
| 7736 | |
| 7737 | // The second restart. |
| 7738 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7739 | "Host: origin:443\r\n" |
| 7740 | "Proxy-Connection: keep-alive\r\n" |
| 7741 | "Proxy-Authorization: NTLM "), |
| 7742 | MockWrite(authenticate_msg.c_str()), |
| 7743 | // End headers. |
| 7744 | MockWrite("\r\n\r\n"), |
| 7745 | }; |
| 7746 | |
| 7747 | MockRead data_reads[] = { |
| 7748 | // The initial NTLM response. |
| 7749 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 7750 | "Content-Length: 0\r\n" |
| 7751 | "Proxy-Authenticate: NTLM\r\n\r\n"), |
| 7752 | |
| 7753 | // The NTLM challenge message. |
| 7754 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 7755 | "Content-Length: 0\r\n" |
| 7756 | "Proxy-Authenticate: NTLM "), |
| 7757 | MockRead(challenge_msg.c_str()), |
| 7758 | // End headers. |
| 7759 | MockRead("\r\n\r\n"), |
| 7760 | |
| 7761 | // Finally the tunnel is established. |
| 7762 | MockRead("HTTP/1.1 200 Connected\r\n\r\n"), |
| 7763 | }; |
| 7764 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7765 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7766 | SSLSocketDataProvider data_ssl(ASYNC, ERR_CONNECTION_RESET); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7767 | StaticSocketDataProvider data2(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7768 | SSLSocketDataProvider data_ssl2(ASYNC, ERR_CONNECTION_RESET); |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 7769 | data_ssl2.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7770 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7771 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl); |
| 7772 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7773 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl2); |
| 7774 | |
| 7775 | // Start the transaction. The proxy responds with an NTLM authentication |
| 7776 | // request. |
| 7777 | TestCompletionCallback callback; |
| 7778 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7779 | int rv = callback.GetResult( |
| 7780 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 7781 | |
| 7782 | EXPECT_THAT(rv, IsOk()); |
| 7783 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7784 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7785 | ASSERT_TRUE(response); |
| 7786 | EXPECT_TRUE(CheckNTLMProxyAuth(response->auth_challenge.get())); |
| 7787 | |
| 7788 | // Configure credentials. The proxy responds with the challenge message. |
| 7789 | rv = callback.GetResult(trans.RestartWithAuth( |
| 7790 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7791 | callback.callback())); |
| 7792 | EXPECT_THAT(rv, IsOk()); |
| 7793 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7794 | response = trans.GetResponseInfo(); |
| 7795 | ASSERT_TRUE(response); |
| 7796 | EXPECT_FALSE(response->auth_challenge); |
| 7797 | |
| 7798 | // Restart once more. The tunnel will be established and the the SSL handshake |
| 7799 | // will reset. The TLS 1.3 version interference probe will then kick in and |
| 7800 | // restart the process. The proxy responds with another NTLM authentiation |
| 7801 | // request, but we don't need to provide credentials as the cached ones work/ |
| 7802 | rv = callback.GetResult( |
| 7803 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7804 | EXPECT_THAT(rv, IsOk()); |
| 7805 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7806 | response = trans.GetResponseInfo(); |
| 7807 | ASSERT_TRUE(response); |
| 7808 | EXPECT_FALSE(response->auth_challenge); |
| 7809 | |
| 7810 | // The proxy responds with the NTLM challenge message. |
| 7811 | rv = callback.GetResult( |
| 7812 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7813 | EXPECT_THAT(rv, IsOk()); |
| 7814 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7815 | response = trans.GetResponseInfo(); |
| 7816 | ASSERT_TRUE(response); |
| 7817 | EXPECT_FALSE(response->auth_challenge); |
| 7818 | |
| 7819 | // Send the NTLM authenticate message. The tunnel is established and the |
| 7820 | // handshake resets again. We should not retry again. |
| 7821 | rv = callback.GetResult( |
| 7822 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7823 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
| 7824 | } |
| 7825 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7826 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7827 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7828 | // Test reading a server response which has only headers, and no body. |
| 7829 | // After some maximum number of bytes is consumed, the transaction should |
| 7830 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7831 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7832 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7833 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7834 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7835 | request.traffic_annotation = |
| 7836 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7837 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7838 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7839 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7840 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7841 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 7842 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7843 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7844 | |
| 7845 | MockRead data_reads[] = { |
| 7846 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7847 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7848 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7849 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7850 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7851 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7852 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7853 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7854 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7855 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7856 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7857 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7858 | |
| 7859 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7860 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7861 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7862 | |
| 7863 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 7864 | // establish tunnel. |
| 7865 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7866 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7867 | HttpRequestInfo request; |
| 7868 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7869 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7870 | request.traffic_annotation = |
| 7871 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7872 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7873 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 7874 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 7875 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 7876 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7877 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7878 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7879 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7880 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7881 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7882 | // Since we have proxy, should try to establish tunnel. |
| 7883 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7884 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7885 | "Host: www.example.org:443\r\n" |
| 7886 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7887 | }; |
| 7888 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7889 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7890 | // connection. Usually a proxy would return 501 (not implemented), |
| 7891 | // or 200 (tunnel established). |
| 7892 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 7893 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7894 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7895 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7896 | }; |
| 7897 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7898 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7899 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7900 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7901 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7902 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7903 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7904 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7905 | |
| 7906 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7907 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7908 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7909 | // Empty the current queue. This is necessary because idle sockets are |
| 7910 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7911 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7912 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7913 | // We now check to make sure the TCPClientSocket was not added back to |
| 7914 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7915 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7916 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7917 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7918 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7919 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7920 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7921 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7922 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7923 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7924 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7925 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7926 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7927 | request.traffic_annotation = |
| 7928 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7929 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7930 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7931 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7932 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7933 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7934 | MockRead data_reads[] = { |
| 7935 | // A part of the response body is received with the response headers. |
| 7936 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7937 | // The rest of the response body is received in two parts. |
| 7938 | MockRead("lo"), |
| 7939 | MockRead(" world"), |
| 7940 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7941 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7942 | }; |
| 7943 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7944 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7945 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7946 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7947 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7948 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7949 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7950 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7951 | |
| 7952 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7953 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7954 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7955 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7956 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7957 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7958 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7959 | std::string status_line = response->headers->GetStatusLine(); |
| 7960 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7961 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7962 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7963 | |
| 7964 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7965 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7966 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7967 | EXPECT_EQ("hello world", response_data); |
| 7968 | |
| 7969 | // Empty the current queue. This is necessary because idle sockets are |
| 7970 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7971 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7972 | |
| 7973 | // 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] | 7974 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7975 | } |
| 7976 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7977 | // Make sure that we recycle a SSL socket after reading all of the response |
| 7978 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7979 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7980 | HttpRequestInfo request; |
| 7981 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7982 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7983 | request.traffic_annotation = |
| 7984 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7985 | |
| 7986 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7987 | MockWrite( |
| 7988 | "GET / HTTP/1.1\r\n" |
| 7989 | "Host: www.example.org\r\n" |
| 7990 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7991 | }; |
| 7992 | |
| 7993 | MockRead data_reads[] = { |
| 7994 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7995 | MockRead("Content-Length: 11\r\n\r\n"), |
| 7996 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7997 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7998 | }; |
| 7999 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8000 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8001 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8002 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8003 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8004 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8005 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8006 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8007 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8008 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8009 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8010 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8011 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8012 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8013 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8014 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8015 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8016 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8017 | ASSERT_TRUE(response); |
| 8018 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8019 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8020 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8021 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8022 | |
| 8023 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8024 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8025 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8026 | EXPECT_EQ("hello world", response_data); |
| 8027 | |
| 8028 | // Empty the current queue. This is necessary because idle sockets are |
| 8029 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8030 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8031 | |
| 8032 | // 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] | 8033 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8034 | } |
| 8035 | |
| 8036 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 8037 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8038 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8039 | HttpRequestInfo request; |
| 8040 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8041 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8042 | request.traffic_annotation = |
| 8043 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8044 | |
| 8045 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8046 | MockWrite( |
| 8047 | "GET / HTTP/1.1\r\n" |
| 8048 | "Host: www.example.org\r\n" |
| 8049 | "Connection: keep-alive\r\n\r\n"), |
| 8050 | MockWrite( |
| 8051 | "GET / HTTP/1.1\r\n" |
| 8052 | "Host: www.example.org\r\n" |
| 8053 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8054 | }; |
| 8055 | |
| 8056 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 8057 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8058 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8059 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8060 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8061 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8062 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8063 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8064 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8065 | StaticSocketDataProvider data(data_reads, data_writes); |
| 8066 | StaticSocketDataProvider data2(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8067 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8068 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8069 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8070 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8071 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8072 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8073 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8074 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8075 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8076 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8077 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8078 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8079 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8080 | |
| 8081 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8082 | ASSERT_TRUE(response); |
| 8083 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8084 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8085 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8086 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8087 | |
| 8088 | std::string response_data; |
| 8089 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8090 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8091 | EXPECT_EQ("hello world", response_data); |
| 8092 | |
| 8093 | // Empty the current queue. This is necessary because idle sockets are |
| 8094 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8095 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8096 | |
| 8097 | // 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] | 8098 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8099 | |
| 8100 | // Now start the second transaction, which should reuse the previous socket. |
| 8101 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8102 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8103 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8104 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8105 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8106 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8107 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8108 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8109 | |
| 8110 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8111 | ASSERT_TRUE(response); |
| 8112 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8113 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8114 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8115 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8116 | |
| 8117 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8118 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8119 | EXPECT_EQ("hello world", response_data); |
| 8120 | |
| 8121 | // Empty the current queue. This is necessary because idle sockets are |
| 8122 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8123 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8124 | |
| 8125 | // 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] | 8126 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8127 | } |
| 8128 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8129 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8130 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8131 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8132 | HttpRequestInfo request; |
| 8133 | request.method = "GET"; |
| 8134 | request.url = GURL("http://www.example.org/"); |
| 8135 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8136 | request.traffic_annotation = |
| 8137 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8138 | |
| 8139 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8140 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8141 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8142 | |
| 8143 | MockRead data_reads[] = { |
| 8144 | // A part of the response body is received with the response headers. |
| 8145 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8146 | // The rest of the response body is received in two parts. |
| 8147 | MockRead("lo"), MockRead(" world"), |
| 8148 | MockRead("junk"), // Should not be read!! |
| 8149 | MockRead(SYNCHRONOUS, OK), |
| 8150 | }; |
| 8151 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8152 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8153 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8154 | |
| 8155 | TestCompletionCallback callback; |
| 8156 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8157 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8158 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8159 | |
| 8160 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8161 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8162 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8163 | ASSERT_TRUE(response); |
| 8164 | EXPECT_TRUE(response->headers); |
| 8165 | std::string status_line = response->headers->GetStatusLine(); |
| 8166 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8167 | |
| 8168 | // Make memory critical notification and ensure the transaction still has been |
| 8169 | // operating right. |
| 8170 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8171 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8172 | base::RunLoop().RunUntilIdle(); |
| 8173 | |
| 8174 | // Socket should not be flushed as long as it is not idle. |
| 8175 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8176 | |
| 8177 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8178 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8179 | EXPECT_THAT(rv, IsOk()); |
| 8180 | EXPECT_EQ("hello world", response_data); |
| 8181 | |
| 8182 | // Empty the current queue. This is necessary because idle sockets are |
| 8183 | // added to the connection pool asynchronously with a PostTask. |
| 8184 | base::RunLoop().RunUntilIdle(); |
| 8185 | |
| 8186 | // We now check to make sure the socket was added back to the pool. |
| 8187 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8188 | |
| 8189 | // Idle sockets should be flushed now. |
| 8190 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8191 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8192 | base::RunLoop().RunUntilIdle(); |
| 8193 | |
| 8194 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8195 | } |
| 8196 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8197 | // Disable idle socket closing on memory pressure. |
| 8198 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8199 | // low memory notification and ensure the socket pool is NOT flushed. |
| 8200 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 8201 | HttpRequestInfo request; |
| 8202 | request.method = "GET"; |
| 8203 | request.url = GURL("http://www.example.org/"); |
| 8204 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8205 | request.traffic_annotation = |
| 8206 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8207 | |
| 8208 | // Disable idle socket closing on memory pressure. |
| 8209 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 8210 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8211 | |
| 8212 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 8213 | |
| 8214 | MockRead data_reads[] = { |
| 8215 | // A part of the response body is received with the response headers. |
| 8216 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8217 | // The rest of the response body is received in two parts. |
| 8218 | MockRead("lo"), MockRead(" world"), |
| 8219 | MockRead("junk"), // Should not be read!! |
| 8220 | MockRead(SYNCHRONOUS, OK), |
| 8221 | }; |
| 8222 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8223 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8224 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8225 | |
| 8226 | TestCompletionCallback callback; |
| 8227 | |
| 8228 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 8229 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8230 | |
| 8231 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8232 | |
| 8233 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 8234 | ASSERT_TRUE(response); |
| 8235 | EXPECT_TRUE(response->headers); |
| 8236 | std::string status_line = response->headers->GetStatusLine(); |
| 8237 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8238 | |
| 8239 | // Make memory critical notification and ensure the transaction still has been |
| 8240 | // operating right. |
| 8241 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8242 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8243 | base::RunLoop().RunUntilIdle(); |
| 8244 | |
| 8245 | // Socket should not be flushed as long as it is not idle. |
| 8246 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8247 | |
| 8248 | std::string response_data; |
| 8249 | rv = ReadTransaction(&trans, &response_data); |
| 8250 | EXPECT_THAT(rv, IsOk()); |
| 8251 | EXPECT_EQ("hello world", response_data); |
| 8252 | |
| 8253 | // Empty the current queue. This is necessary because idle sockets are |
| 8254 | // added to the connection pool asynchronously with a PostTask. |
| 8255 | base::RunLoop().RunUntilIdle(); |
| 8256 | |
| 8257 | // We now check to make sure the socket was added back to the pool. |
| 8258 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8259 | |
| 8260 | // Idle sockets should NOT be flushed on moderate memory pressure. |
| 8261 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8262 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 8263 | base::RunLoop().RunUntilIdle(); |
| 8264 | |
| 8265 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8266 | |
| 8267 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 8268 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8269 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8270 | base::RunLoop().RunUntilIdle(); |
| 8271 | |
| 8272 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8273 | } |
| 8274 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8275 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 8276 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8277 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8278 | HttpRequestInfo request; |
| 8279 | request.method = "GET"; |
| 8280 | request.url = GURL("https://www.example.org/"); |
| 8281 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8282 | request.traffic_annotation = |
| 8283 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8284 | |
| 8285 | MockWrite data_writes[] = { |
| 8286 | MockWrite("GET / HTTP/1.1\r\n" |
| 8287 | "Host: www.example.org\r\n" |
| 8288 | "Connection: keep-alive\r\n\r\n"), |
| 8289 | }; |
| 8290 | |
| 8291 | MockRead data_reads[] = { |
| 8292 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8293 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 8294 | |
| 8295 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8296 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8297 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8298 | StaticSocketDataProvider data(data_reads, data_writes); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8299 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8300 | |
| 8301 | TestCompletionCallback callback; |
| 8302 | |
| 8303 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8304 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8305 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8306 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8307 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8308 | |
| 8309 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8310 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8311 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8312 | ASSERT_TRUE(response); |
| 8313 | ASSERT_TRUE(response->headers); |
| 8314 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8315 | |
| 8316 | // Make memory critical notification and ensure the transaction still has been |
| 8317 | // operating right. |
| 8318 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8319 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8320 | base::RunLoop().RunUntilIdle(); |
| 8321 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8322 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8323 | |
| 8324 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8325 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8326 | EXPECT_THAT(rv, IsOk()); |
| 8327 | EXPECT_EQ("hello world", response_data); |
| 8328 | |
| 8329 | // Empty the current queue. This is necessary because idle sockets are |
| 8330 | // added to the connection pool asynchronously with a PostTask. |
| 8331 | base::RunLoop().RunUntilIdle(); |
| 8332 | |
| 8333 | // 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] | 8334 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8335 | |
| 8336 | // Make memory notification once again and ensure idle socket is closed. |
| 8337 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8338 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8339 | base::RunLoop().RunUntilIdle(); |
| 8340 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8341 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8342 | } |
| 8343 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8344 | // Make sure that we recycle a socket after a zero-length response. |
| 8345 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8346 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8347 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8348 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8349 | request.url = GURL( |
| 8350 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 8351 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 8352 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 8353 | "rt=prt.2642,ol.2649,xjs.2951"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8354 | request.traffic_annotation = |
| 8355 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8356 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8357 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8358 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8359 | MockRead data_reads[] = { |
| 8360 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 8361 | "Content-Length: 0\r\n" |
| 8362 | "Content-Type: text/html\r\n\r\n"), |
| 8363 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8364 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8365 | }; |
| 8366 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8367 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8368 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8369 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8370 | // Transaction must be created after the MockReads, so it's destroyed before |
| 8371 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8372 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8373 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8374 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8375 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8376 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8377 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8378 | |
| 8379 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8380 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8381 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8382 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8383 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8384 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8385 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8386 | std::string status_line = response->headers->GetStatusLine(); |
| 8387 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 8388 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8389 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8390 | |
| 8391 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8392 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8393 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8394 | EXPECT_EQ("", response_data); |
| 8395 | |
| 8396 | // Empty the current queue. This is necessary because idle sockets are |
| 8397 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8398 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8399 | |
| 8400 | // 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] | 8401 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8402 | } |
| 8403 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8404 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8405 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8406 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8407 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8408 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8409 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8410 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8411 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 8412 | // after use. |
| 8413 | request[0].method = "GET"; |
| 8414 | request[0].url = GURL("http://www.google.com/"); |
| 8415 | request[0].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8416 | request[0].traffic_annotation = |
| 8417 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8418 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 8419 | // transaction 1. The first attempts fails when writing the POST data. |
| 8420 | // This causes the transaction to retry with a new socket. The second |
| 8421 | // attempt succeeds. |
| 8422 | request[1].method = "POST"; |
| 8423 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8424 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8425 | request[1].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8426 | request[1].traffic_annotation = |
| 8427 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8428 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8429 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8430 | |
| 8431 | // The first socket is used for transaction 1 and the first attempt of |
| 8432 | // transaction 2. |
| 8433 | |
| 8434 | // The response of transaction 1. |
| 8435 | MockRead data_reads1[] = { |
| 8436 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 8437 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8438 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8439 | }; |
| 8440 | // The mock write results of transaction 1 and the first attempt of |
| 8441 | // transaction 2. |
| 8442 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8443 | MockWrite(SYNCHRONOUS, 64), // GET |
| 8444 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8445 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8446 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8447 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8448 | |
| 8449 | // The second socket is used for the second attempt of transaction 2. |
| 8450 | |
| 8451 | // The response of transaction 2. |
| 8452 | MockRead data_reads2[] = { |
| 8453 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 8454 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8455 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8456 | }; |
| 8457 | // The mock write results of the second attempt of transaction 2. |
| 8458 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8459 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8460 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8461 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8462 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8463 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8464 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8465 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8466 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8467 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8468 | "hello world", "welcome" |
| 8469 | }; |
| 8470 | |
| 8471 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8472 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8473 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8474 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8475 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8476 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8477 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8478 | |
| 8479 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8480 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8481 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8482 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8483 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8484 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8485 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8486 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8487 | |
| 8488 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8489 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8490 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8491 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 8492 | } |
| 8493 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8494 | |
| 8495 | // Test the request-challenge-retry sequence for basic auth when there is |
| 8496 | // 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] | 8497 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8498 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8499 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8500 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8501 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 8502 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8503 | request.traffic_annotation = |
| 8504 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8505 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8506 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8507 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8508 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8509 | // The password contains an escaped character -- for this test to pass it |
| 8510 | // will need to be unescaped by HttpNetworkTransaction. |
| 8511 | EXPECT_EQ("b%40r", request.url.password()); |
| 8512 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8513 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8514 | MockWrite( |
| 8515 | "GET / HTTP/1.1\r\n" |
| 8516 | "Host: www.example.org\r\n" |
| 8517 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8518 | }; |
| 8519 | |
| 8520 | MockRead data_reads1[] = { |
| 8521 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8522 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8523 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8524 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8525 | }; |
| 8526 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8527 | // After the challenge above, the transaction will be restarted using the |
| 8528 | // identity from the url (foo, b@r) to answer the challenge. |
| 8529 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8530 | MockWrite( |
| 8531 | "GET / HTTP/1.1\r\n" |
| 8532 | "Host: www.example.org\r\n" |
| 8533 | "Connection: keep-alive\r\n" |
| 8534 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8535 | }; |
| 8536 | |
| 8537 | MockRead data_reads2[] = { |
| 8538 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8539 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8540 | MockRead(SYNCHRONOUS, OK), |
| 8541 | }; |
| 8542 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8543 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8544 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8545 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8546 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8547 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8548 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8549 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8550 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8551 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8552 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8553 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8554 | |
| 8555 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8556 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8557 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8558 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8559 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8560 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8561 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8562 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8563 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8564 | |
| 8565 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8566 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8567 | |
| 8568 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8569 | |
| 8570 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8571 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8572 | } |
| 8573 | |
| 8574 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 8575 | // incorrect identity in the URL. The identity from the URL should be used only |
| 8576 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8577 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8578 | HttpRequestInfo request; |
| 8579 | request.method = "GET"; |
| 8580 | // Note: the URL has a username:password in it. The password "baz" is |
| 8581 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8582 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8583 | |
| 8584 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8585 | request.traffic_annotation = |
| 8586 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8587 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8588 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8589 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8590 | |
| 8591 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8592 | MockWrite( |
| 8593 | "GET / HTTP/1.1\r\n" |
| 8594 | "Host: www.example.org\r\n" |
| 8595 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8596 | }; |
| 8597 | |
| 8598 | MockRead data_reads1[] = { |
| 8599 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8600 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8601 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8602 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8603 | }; |
| 8604 | |
| 8605 | // After the challenge above, the transaction will be restarted using the |
| 8606 | // identity from the url (foo, baz) to answer the challenge. |
| 8607 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8608 | MockWrite( |
| 8609 | "GET / HTTP/1.1\r\n" |
| 8610 | "Host: www.example.org\r\n" |
| 8611 | "Connection: keep-alive\r\n" |
| 8612 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8613 | }; |
| 8614 | |
| 8615 | MockRead data_reads2[] = { |
| 8616 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8617 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8618 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8619 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8620 | }; |
| 8621 | |
| 8622 | // After the challenge above, the transaction will be restarted using the |
| 8623 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 8624 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8625 | MockWrite( |
| 8626 | "GET / HTTP/1.1\r\n" |
| 8627 | "Host: www.example.org\r\n" |
| 8628 | "Connection: keep-alive\r\n" |
| 8629 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8630 | }; |
| 8631 | |
| 8632 | MockRead data_reads3[] = { |
| 8633 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8634 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8635 | MockRead(SYNCHRONOUS, OK), |
| 8636 | }; |
| 8637 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8638 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8639 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 8640 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8641 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8642 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8643 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8644 | |
| 8645 | TestCompletionCallback callback1; |
| 8646 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8647 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8648 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8649 | |
| 8650 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8651 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8652 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8653 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8654 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8655 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8656 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8657 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8658 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8659 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8660 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8661 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8662 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8663 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 8664 | |
| 8665 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8666 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8667 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8668 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8669 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8670 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8671 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8672 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8673 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8674 | |
| 8675 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8676 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8677 | |
| 8678 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8679 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8680 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8681 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8682 | } |
| 8683 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8684 | |
| 8685 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 8686 | // correct identity in the URL, but its use is being suppressed. The identity |
| 8687 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8688 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8689 | HttpRequestInfo request; |
| 8690 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8691 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8692 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8693 | request.traffic_annotation = |
| 8694 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8695 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8696 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8697 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8698 | |
| 8699 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8700 | MockWrite( |
| 8701 | "GET / HTTP/1.1\r\n" |
| 8702 | "Host: www.example.org\r\n" |
| 8703 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8704 | }; |
| 8705 | |
| 8706 | MockRead data_reads1[] = { |
| 8707 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8708 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8709 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8710 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8711 | }; |
| 8712 | |
| 8713 | // After the challenge above, the transaction will be restarted using the |
| 8714 | // identity supplied by the user, not the one in the URL, to answer the |
| 8715 | // challenge. |
| 8716 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8717 | MockWrite( |
| 8718 | "GET / HTTP/1.1\r\n" |
| 8719 | "Host: www.example.org\r\n" |
| 8720 | "Connection: keep-alive\r\n" |
| 8721 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8722 | }; |
| 8723 | |
| 8724 | MockRead data_reads3[] = { |
| 8725 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8726 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8727 | MockRead(SYNCHRONOUS, OK), |
| 8728 | }; |
| 8729 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8730 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8731 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8732 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8733 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 8734 | |
| 8735 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8736 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8737 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8738 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8739 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8740 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8741 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8742 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8743 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8744 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 8745 | |
| 8746 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8747 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8748 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8749 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8750 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8751 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8752 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8753 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8754 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8755 | |
| 8756 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8757 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8758 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8759 | |
| 8760 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8761 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8762 | } |
| 8763 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8764 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8765 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8766 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8767 | |
| 8768 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 8769 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8770 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8771 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8772 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8773 | request.traffic_annotation = |
| 8774 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8775 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8776 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8777 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8778 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8779 | MockWrite( |
| 8780 | "GET /x/y/z HTTP/1.1\r\n" |
| 8781 | "Host: www.example.org\r\n" |
| 8782 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8783 | }; |
| 8784 | |
| 8785 | MockRead data_reads1[] = { |
| 8786 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8787 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8788 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8789 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8790 | }; |
| 8791 | |
| 8792 | // Resend with authorization (username=foo, password=bar) |
| 8793 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8794 | MockWrite( |
| 8795 | "GET /x/y/z HTTP/1.1\r\n" |
| 8796 | "Host: www.example.org\r\n" |
| 8797 | "Connection: keep-alive\r\n" |
| 8798 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8799 | }; |
| 8800 | |
| 8801 | // Sever accepts the authorization. |
| 8802 | MockRead data_reads2[] = { |
| 8803 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8804 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8805 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8806 | }; |
| 8807 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8808 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8809 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8810 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8811 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8812 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8813 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8814 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8815 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8816 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8817 | |
| 8818 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8819 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8820 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8821 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8822 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8823 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8824 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8825 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8826 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8827 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8828 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8829 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8830 | |
| 8831 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8832 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8833 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8834 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8835 | ASSERT_TRUE(response); |
| 8836 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8837 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8838 | } |
| 8839 | |
| 8840 | // ------------------------------------------------------------------------ |
| 8841 | |
| 8842 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 8843 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8844 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8845 | request.method = "GET"; |
| 8846 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 8847 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8848 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8849 | request.traffic_annotation = |
| 8850 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8851 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8852 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8853 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8854 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8855 | MockWrite( |
| 8856 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8857 | "Host: www.example.org\r\n" |
| 8858 | "Connection: keep-alive\r\n" |
| 8859 | // Send preemptive authorization for MyRealm1 |
| 8860 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8861 | }; |
| 8862 | |
| 8863 | // The server didn't like the preemptive authorization, and |
| 8864 | // challenges us for a different realm (MyRealm2). |
| 8865 | MockRead data_reads1[] = { |
| 8866 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8867 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 8868 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8869 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8870 | }; |
| 8871 | |
| 8872 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 8873 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8874 | MockWrite( |
| 8875 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8876 | "Host: www.example.org\r\n" |
| 8877 | "Connection: keep-alive\r\n" |
| 8878 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8879 | }; |
| 8880 | |
| 8881 | // Sever accepts the authorization. |
| 8882 | MockRead data_reads2[] = { |
| 8883 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8884 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8885 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8886 | }; |
| 8887 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8888 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8889 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8890 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8891 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8892 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8893 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8894 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8895 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8896 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8897 | |
| 8898 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8899 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8900 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8901 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8902 | ASSERT_TRUE(response); |
| 8903 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8904 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8905 | EXPECT_EQ("http://www.example.org", |
| 8906 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8907 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 8908 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8909 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8910 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8911 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8912 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 8913 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8914 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8915 | |
| 8916 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8917 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8918 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8919 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8920 | ASSERT_TRUE(response); |
| 8921 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8922 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8923 | } |
| 8924 | |
| 8925 | // ------------------------------------------------------------------------ |
| 8926 | |
| 8927 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 8928 | // succeed with preemptive authorization. |
| 8929 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8930 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8931 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8932 | request.url = GURL("http://www.example.org/x/y/z2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8933 | request.traffic_annotation = |
| 8934 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8935 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8936 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8937 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8938 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8939 | MockWrite( |
| 8940 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 8941 | "Host: www.example.org\r\n" |
| 8942 | "Connection: keep-alive\r\n" |
| 8943 | // The authorization for MyRealm1 gets sent preemptively |
| 8944 | // (since the url is in the same protection space) |
| 8945 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8946 | }; |
| 8947 | |
| 8948 | // Sever accepts the preemptive authorization |
| 8949 | MockRead data_reads1[] = { |
| 8950 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8951 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8952 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8953 | }; |
| 8954 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8955 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8956 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8957 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8958 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8959 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8960 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8961 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8962 | |
| 8963 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8964 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8965 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8966 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8967 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8968 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8969 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8970 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8971 | } |
| 8972 | |
| 8973 | // ------------------------------------------------------------------------ |
| 8974 | |
| 8975 | // Transaction 4: request another URL in MyRealm (however the |
| 8976 | // url is not known to belong to the protection space, so no pre-auth). |
| 8977 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8978 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8979 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8980 | request.url = GURL("http://www.example.org/x/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8981 | request.traffic_annotation = |
| 8982 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8983 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8984 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8985 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8986 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8987 | MockWrite( |
| 8988 | "GET /x/1 HTTP/1.1\r\n" |
| 8989 | "Host: www.example.org\r\n" |
| 8990 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8991 | }; |
| 8992 | |
| 8993 | MockRead data_reads1[] = { |
| 8994 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8995 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8996 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8997 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8998 | }; |
| 8999 | |
| 9000 | // Resend with authorization from MyRealm's cache. |
| 9001 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9002 | MockWrite( |
| 9003 | "GET /x/1 HTTP/1.1\r\n" |
| 9004 | "Host: www.example.org\r\n" |
| 9005 | "Connection: keep-alive\r\n" |
| 9006 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9007 | }; |
| 9008 | |
| 9009 | // Sever accepts the authorization. |
| 9010 | MockRead data_reads2[] = { |
| 9011 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9012 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9013 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9014 | }; |
| 9015 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9016 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9017 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9018 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9019 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9020 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9021 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9022 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9023 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9024 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9025 | |
| 9026 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9027 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9028 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9029 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9030 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9031 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9032 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9033 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9034 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9035 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9036 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9037 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9038 | ASSERT_TRUE(response); |
| 9039 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9040 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9041 | } |
| 9042 | |
| 9043 | // ------------------------------------------------------------------------ |
| 9044 | |
| 9045 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 9046 | // cached identity. Should invalidate and re-prompt. |
| 9047 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9048 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9049 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9050 | request.url = GURL("http://www.example.org/p/q/t"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9051 | request.traffic_annotation = |
| 9052 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9053 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9054 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9055 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9056 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9057 | MockWrite( |
| 9058 | "GET /p/q/t HTTP/1.1\r\n" |
| 9059 | "Host: www.example.org\r\n" |
| 9060 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9061 | }; |
| 9062 | |
| 9063 | MockRead data_reads1[] = { |
| 9064 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9065 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9066 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9067 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9068 | }; |
| 9069 | |
| 9070 | // Resend with authorization from cache for MyRealm. |
| 9071 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9072 | MockWrite( |
| 9073 | "GET /p/q/t HTTP/1.1\r\n" |
| 9074 | "Host: www.example.org\r\n" |
| 9075 | "Connection: keep-alive\r\n" |
| 9076 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9077 | }; |
| 9078 | |
| 9079 | // Sever rejects the authorization. |
| 9080 | MockRead data_reads2[] = { |
| 9081 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9082 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9083 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9084 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9085 | }; |
| 9086 | |
| 9087 | // At this point we should prompt for new credentials for MyRealm. |
| 9088 | // Restart with username=foo3, password=foo4. |
| 9089 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9090 | MockWrite( |
| 9091 | "GET /p/q/t HTTP/1.1\r\n" |
| 9092 | "Host: www.example.org\r\n" |
| 9093 | "Connection: keep-alive\r\n" |
| 9094 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9095 | }; |
| 9096 | |
| 9097 | // Sever accepts the authorization. |
| 9098 | MockRead data_reads3[] = { |
| 9099 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9100 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9101 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9102 | }; |
| 9103 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9104 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9105 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 9106 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9107 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9108 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9109 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9110 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9111 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9112 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9113 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9114 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9115 | |
| 9116 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9117 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9118 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9119 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9120 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9121 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9122 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9123 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9124 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9125 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9126 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9127 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9128 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9129 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9130 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9131 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9132 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9133 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 9134 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9135 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9136 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9137 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9138 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9139 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9140 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9141 | ASSERT_TRUE(response); |
| 9142 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9143 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9144 | } |
| 9145 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9146 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9147 | // Tests that nonce count increments when multiple auth attempts |
| 9148 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9149 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 9150 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 9151 | new HttpAuthHandlerDigest::Factory(); |
| 9152 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 9153 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 9154 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9155 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9156 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9157 | |
| 9158 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 9159 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9160 | HttpRequestInfo request; |
| 9161 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9162 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9163 | request.traffic_annotation = |
| 9164 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9165 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9166 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9167 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9168 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9169 | MockWrite( |
| 9170 | "GET /x/y/z HTTP/1.1\r\n" |
| 9171 | "Host: www.example.org\r\n" |
| 9172 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9173 | }; |
| 9174 | |
| 9175 | MockRead data_reads1[] = { |
| 9176 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9177 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 9178 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9179 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9180 | }; |
| 9181 | |
| 9182 | // Resend with authorization (username=foo, password=bar) |
| 9183 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9184 | MockWrite( |
| 9185 | "GET /x/y/z HTTP/1.1\r\n" |
| 9186 | "Host: www.example.org\r\n" |
| 9187 | "Connection: keep-alive\r\n" |
| 9188 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9189 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 9190 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 9191 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9192 | }; |
| 9193 | |
| 9194 | // Sever accepts the authorization. |
| 9195 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9196 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9197 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9198 | }; |
| 9199 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9200 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9201 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9202 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9203 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9204 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9205 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9206 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9207 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9208 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9209 | |
| 9210 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9211 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9212 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9213 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9214 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9215 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9216 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9217 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9218 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9219 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9220 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9221 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9222 | |
| 9223 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9224 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9225 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9226 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9227 | ASSERT_TRUE(response); |
| 9228 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9229 | } |
| 9230 | |
| 9231 | // ------------------------------------------------------------------------ |
| 9232 | |
| 9233 | // Transaction 2: Request another resource in digestive's protection space. |
| 9234 | // This will preemptively add an Authorization header which should have an |
| 9235 | // "nc" value of 2 (as compared to 1 in the first use. |
| 9236 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9237 | HttpRequestInfo request; |
| 9238 | request.method = "GET"; |
| 9239 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 9240 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9241 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9242 | request.traffic_annotation = |
| 9243 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9244 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9245 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9246 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9247 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9248 | MockWrite( |
| 9249 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 9250 | "Host: www.example.org\r\n" |
| 9251 | "Connection: keep-alive\r\n" |
| 9252 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9253 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 9254 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 9255 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9256 | }; |
| 9257 | |
| 9258 | // Sever accepts the authorization. |
| 9259 | MockRead data_reads1[] = { |
| 9260 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9261 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9262 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9263 | }; |
| 9264 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9265 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9266 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9267 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9268 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9269 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9270 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9271 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9272 | |
| 9273 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9274 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9275 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9276 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9277 | ASSERT_TRUE(response); |
| 9278 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9279 | } |
| 9280 | } |
| 9281 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9282 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9283 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9284 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9285 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9286 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9287 | |
| 9288 | // Setup some state (which we expect ResetStateForRestart() will clear). |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 9289 | trans.read_buf_ = base::MakeRefCounted<IOBuffer>(15); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9290 | trans.read_buf_len_ = 15; |
| 9291 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9292 | |
| 9293 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9294 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9295 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9296 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9297 | response->response_time = base::Time::Now(); |
| 9298 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9299 | |
| 9300 | { // Setup state for response_.vary_data |
| 9301 | HttpRequestInfo request; |
| 9302 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 9303 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 9304 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9305 | request.extra_headers.SetHeader("Foo", "1"); |
| 9306 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9307 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9308 | } |
| 9309 | |
| 9310 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9311 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9312 | |
| 9313 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9314 | EXPECT_FALSE(trans.read_buf_); |
| 9315 | EXPECT_EQ(0, trans.read_buf_len_); |
| 9316 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9317 | EXPECT_FALSE(response->auth_challenge); |
| 9318 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 9319 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9320 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9321 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9322 | } |
| 9323 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9324 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9325 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9326 | HttpRequestInfo request; |
| 9327 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9328 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9329 | request.traffic_annotation = |
| 9330 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9331 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9332 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9333 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9334 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9335 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9336 | MockWrite( |
| 9337 | "GET / HTTP/1.1\r\n" |
| 9338 | "Host: www.example.org\r\n" |
| 9339 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9340 | }; |
| 9341 | |
| 9342 | MockRead data_reads[] = { |
| 9343 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9344 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9345 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9346 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9347 | }; |
| 9348 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 9349 | StaticSocketDataProvider ssl_bad_certificate; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9350 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9351 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9352 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9353 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9354 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9355 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9356 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9357 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9358 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9359 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9360 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9361 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9362 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9363 | |
| 9364 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9365 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9366 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9367 | rv = trans.RestartIgnoringLastError(callback.callback()); |
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, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9372 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9373 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9374 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9375 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9376 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9377 | } |
| 9378 | |
| 9379 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 9380 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9381 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9382 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9383 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9384 | |
| 9385 | HttpRequestInfo request; |
| 9386 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9387 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9388 | request.traffic_annotation = |
| 9389 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9390 | |
| 9391 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9392 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9393 | "Host: www.example.org:443\r\n" |
| 9394 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9395 | }; |
| 9396 | |
| 9397 | MockRead proxy_reads[] = { |
| 9398 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9399 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9400 | }; |
| 9401 | |
| 9402 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9403 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9404 | "Host: www.example.org:443\r\n" |
| 9405 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9406 | MockWrite("GET / HTTP/1.1\r\n" |
| 9407 | "Host: www.example.org\r\n" |
| 9408 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9409 | }; |
| 9410 | |
| 9411 | MockRead data_reads[] = { |
| 9412 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9413 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9414 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9415 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9416 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9417 | }; |
| 9418 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9419 | StaticSocketDataProvider ssl_bad_certificate(proxy_reads, proxy_writes); |
| 9420 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9421 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9422 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9423 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9424 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9425 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9426 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9427 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9428 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9429 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9430 | |
| 9431 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9432 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9433 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9434 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9435 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9436 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9437 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9438 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9439 | |
| 9440 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9441 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9442 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9443 | rv = trans.RestartIgnoringLastError(callback.callback()); |
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, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9448 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9449 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9450 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9451 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9452 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9453 | } |
| 9454 | } |
| 9455 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9456 | |
| 9457 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9458 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9459 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9460 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9461 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9462 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9463 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9464 | |
| 9465 | HttpRequestInfo request; |
| 9466 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9467 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9468 | request.traffic_annotation = |
| 9469 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9470 | |
| 9471 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9472 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9473 | "Host: www.example.org:443\r\n" |
| 9474 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9475 | MockWrite("GET / HTTP/1.1\r\n" |
| 9476 | "Host: www.example.org\r\n" |
| 9477 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9478 | }; |
| 9479 | |
| 9480 | MockRead data_reads[] = { |
| 9481 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9482 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9483 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9484 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9485 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9486 | }; |
| 9487 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9488 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9489 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9490 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9491 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9492 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9493 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9494 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9495 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9496 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9497 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9498 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9499 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9500 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9501 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9502 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9503 | |
| 9504 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9505 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9506 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9507 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9508 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9509 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9510 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9511 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9512 | EXPECT_EQ(200, response->headers->response_code()); |
| 9513 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9514 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9515 | |
| 9516 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9517 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9518 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9519 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9520 | } |
| 9521 | |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9522 | // Test that an HTTPS Proxy can redirect a CONNECT request for main frames. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9523 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9524 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9525 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9526 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9527 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9528 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9529 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9530 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 9531 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 9532 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 9533 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9534 | HttpRequestInfo request; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9535 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9536 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9537 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9538 | request.traffic_annotation = |
| 9539 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9540 | |
| 9541 | MockWrite data_writes[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9542 | MockWrite(ASYNC, 0, |
| 9543 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9544 | "Host: www.example.org:443\r\n" |
| 9545 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9546 | }; |
| 9547 | |
| 9548 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9549 | // Pause on first read. |
| 9550 | MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 9551 | MockRead(ASYNC, 2, "HTTP/1.1 302 Redirect\r\n"), |
| 9552 | MockRead(ASYNC, 3, "Location: http://login.example.com/\r\n"), |
| 9553 | MockRead(ASYNC, 4, "Content-Length: 0\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9554 | }; |
| 9555 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9556 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9557 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9558 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9559 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9560 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9561 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9562 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9563 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9564 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9565 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9566 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9567 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9568 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9569 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
| 9570 | |
| 9571 | // Host resolution takes |kTimeIncrement|. |
| 9572 | FastForwardBy(kTimeIncrement); |
| 9573 | // Resolving the current request with |ResolveNow| will cause the pending |
| 9574 | // request to instantly complete, and the async connect will start as well. |
| 9575 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 9576 | |
| 9577 | // Connecting takes |kTimeIncrement|. |
| 9578 | FastForwardBy(kTimeIncrement); |
| 9579 | data.RunUntilPaused(); |
| 9580 | |
| 9581 | // The server takes |kTimeIncrement| to respond. |
| 9582 | FastForwardBy(kTimeIncrement); |
| 9583 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9584 | |
| 9585 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9586 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9587 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9588 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9589 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9590 | |
| 9591 | EXPECT_EQ(302, response->headers->response_code()); |
| 9592 | std::string url; |
| 9593 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 9594 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9595 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9596 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9597 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9598 | |
| 9599 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 9600 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9601 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9602 | // In the case of redirects from proxies, just as with all responses from |
| 9603 | // proxies, DNS and SSL times reflect timing to look up the destination's |
| 9604 | // name, and negotiate an SSL connection to it (Neither of which are done in |
| 9605 | // this case), which the DNS and SSL times for the proxy are all included in |
| 9606 | // connect_start / connect_end. See |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9607 | // HttpNetworkTransaction::OnHttpsProxyTunnelResponseRedirect |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9608 | |
| 9609 | EXPECT_TRUE(load_timing_info.connect_timing.dns_start.is_null()); |
| 9610 | EXPECT_TRUE(load_timing_info.connect_timing.dns_end.is_null()); |
| 9611 | EXPECT_TRUE(load_timing_info.connect_timing.ssl_start.is_null()); |
| 9612 | EXPECT_TRUE(load_timing_info.connect_timing.ssl_end.is_null()); |
| 9613 | |
| 9614 | EXPECT_EQ(start_time, load_timing_info.proxy_resolve_start); |
| 9615 | EXPECT_EQ(start_time, load_timing_info.proxy_resolve_end); |
| 9616 | EXPECT_EQ(start_time, load_timing_info.connect_timing.connect_start); |
| 9617 | EXPECT_EQ(start_time + 3 * kTimeIncrement, |
| 9618 | load_timing_info.connect_timing.connect_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9619 | |
| 9620 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 9621 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 9622 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9623 | } |
| 9624 | |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9625 | // Test that an HTTPS Proxy cannot redirect a CONNECT request for subresources. |
| 9626 | TEST_F(HttpNetworkTransactionTest, |
| 9627 | RedirectOfHttpsConnectSubresourceViaHttpsProxy) { |
| 9628 | base::HistogramTester histograms; |
| 9629 | session_deps_.proxy_resolution_service = |
| 9630 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9631 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9632 | TestNetLog net_log; |
| 9633 | session_deps_.net_log = &net_log; |
| 9634 | |
| 9635 | HttpRequestInfo request; |
| 9636 | request.method = "GET"; |
| 9637 | request.url = GURL("https://www.example.org/"); |
| 9638 | request.traffic_annotation = |
| 9639 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9640 | |
| 9641 | MockWrite data_writes[] = { |
| 9642 | MockWrite(ASYNC, 0, |
| 9643 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9644 | "Host: www.example.org:443\r\n" |
| 9645 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9646 | }; |
| 9647 | |
| 9648 | MockRead data_reads[] = { |
| 9649 | MockRead(ASYNC, 1, "HTTP/1.1 302 Redirect\r\n"), |
| 9650 | MockRead(ASYNC, 2, "Location: http://login.example.com/\r\n"), |
| 9651 | MockRead(ASYNC, 3, "Content-Length: 0\r\n\r\n"), |
| 9652 | }; |
| 9653 | |
| 9654 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
| 9655 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9656 | |
| 9657 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9658 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9659 | |
| 9660 | TestCompletionCallback callback; |
| 9661 | |
| 9662 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9663 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 9664 | |
| 9665 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 9666 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9667 | |
| 9668 | rv = callback.WaitForResult(); |
| 9669 | EXPECT_THAT(rv, IsError(ERR_HTTPS_PROXY_TUNNEL_RESPONSE_REDIRECT)); |
| 9670 | |
| 9671 | histograms.ExpectUniqueSample( |
| 9672 | "Net.Proxy.RedirectDuringConnect", |
| 9673 | HttpNetworkTransaction::kSubresourceByExplicitProxy, 1); |
| 9674 | } |
| 9675 | |
| 9676 | // Test that an HTTPS Proxy which was auto-detected cannot redirect a CONNECT |
| 9677 | // request for main frames. |
| 9678 | TEST_F(HttpNetworkTransactionTest, |
| 9679 | RedirectOfHttpsConnectViaAutoDetectedHttpsProxy) { |
| 9680 | base::HistogramTester histograms; |
| 9681 | session_deps_.proxy_resolution_service = |
| 9682 | ProxyResolutionService::CreateFixedFromAutoDetectedPacResult( |
| 9683 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9684 | TestNetLog net_log; |
| 9685 | session_deps_.net_log = &net_log; |
| 9686 | |
| 9687 | HttpRequestInfo request; |
| 9688 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
| 9689 | request.method = "GET"; |
| 9690 | request.url = GURL("https://www.example.org/"); |
| 9691 | request.traffic_annotation = |
| 9692 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9693 | |
| 9694 | MockWrite data_writes[] = { |
| 9695 | MockWrite(ASYNC, 0, |
| 9696 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9697 | "Host: www.example.org:443\r\n" |
| 9698 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9699 | }; |
| 9700 | |
| 9701 | MockRead data_reads[] = { |
| 9702 | MockRead(ASYNC, 1, "HTTP/1.1 302 Redirect\r\n"), |
| 9703 | MockRead(ASYNC, 2, "Location: http://login.example.com/\r\n"), |
| 9704 | MockRead(ASYNC, 3, "Content-Length: 0\r\n\r\n"), |
| 9705 | }; |
| 9706 | |
| 9707 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
| 9708 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9709 | |
| 9710 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9711 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9712 | |
| 9713 | TestCompletionCallback callback; |
| 9714 | |
| 9715 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9716 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 9717 | |
| 9718 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 9719 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9720 | |
| 9721 | rv = callback.WaitForResult(); |
| 9722 | EXPECT_THAT(rv, IsError(ERR_HTTPS_PROXY_TUNNEL_RESPONSE_REDIRECT)); |
| 9723 | |
| 9724 | histograms.ExpectUniqueSample( |
| 9725 | "Net.Proxy.RedirectDuringConnect", |
| 9726 | HttpNetworkTransaction::kMainFrameByAutoDetectedProxy, 1); |
| 9727 | } |
| 9728 | |
| 9729 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request for main |
| 9730 | // frames. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9731 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9732 | base::HistogramTester histograms; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9733 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9734 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9735 | TestNetLog net_log; |
| 9736 | session_deps_.net_log = &net_log; |
| 9737 | |
| 9738 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 9739 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 9740 | session_deps_.host_resolver->set_ondemand_mode(true); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9741 | |
| 9742 | HttpRequestInfo request; |
| 9743 | request.method = "GET"; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9744 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9745 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9746 | request.traffic_annotation = |
| 9747 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9748 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9749 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9750 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 9751 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9752 | spdy::SpdySerializedFrame goaway( |
| 9753 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9754 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9755 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9756 | CreateMockWrite(goaway, 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9757 | }; |
| 9758 | |
| 9759 | static const char* const kExtraHeaders[] = { |
| 9760 | "location", |
| 9761 | "http://login.example.com/", |
| 9762 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9763 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9764 | "302", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9765 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9766 | // Pause on first read. |
| 9767 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp, 2), |
| 9768 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9769 | }; |
| 9770 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9771 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9772 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9773 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9774 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9775 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9776 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9777 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9778 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9779 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9780 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9781 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9782 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9783 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9784 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9785 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9786 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9787 | // Host resolution takes |kTimeIncrement|. |
| 9788 | FastForwardBy(kTimeIncrement); |
| 9789 | // Resolving the current request with |ResolveNow| will cause the pending |
| 9790 | // request to instantly complete, and the async connect will start as well. |
| 9791 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 9792 | |
| 9793 | // Connecting takes |kTimeIncrement|. |
| 9794 | FastForwardBy(kTimeIncrement); |
| 9795 | data.RunUntilPaused(); |
| 9796 | |
| 9797 | FastForwardBy(kTimeIncrement); |
| 9798 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9799 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9800 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9801 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9802 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9803 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9804 | |
| 9805 | EXPECT_EQ(302, response->headers->response_code()); |
| 9806 | std::string url; |
| 9807 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 9808 | EXPECT_EQ("http://login.example.com/", url); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9809 | |
| 9810 | LoadTimingInfo load_timing_info; |
| 9811 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 9812 | |
| 9813 | EXPECT_FALSE(load_timing_info.socket_reused); |
| 9814 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
| 9815 | |
| 9816 | // No proxy resolution times, since there's no PAC script. |
| 9817 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 9818 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 9819 | |
| 9820 | // In the case of redirects from proxies, just as with all responses from |
| 9821 | // proxies, DNS and SSL times reflect timing to look up the destination's |
| 9822 | // name, and negotiate an SSL connection to it (Neither of which are done in |
| 9823 | // this case), which the DNS and SSL times for the proxy are all included in |
| 9824 | // connect_start / connect_end. See |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9825 | // HttpNetworkTransaction::OnHttpsProxyTunnelResponseRedirect. |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9826 | |
| 9827 | EXPECT_TRUE(load_timing_info.connect_timing.dns_start.is_null()); |
| 9828 | EXPECT_TRUE(load_timing_info.connect_timing.dns_end.is_null()); |
| 9829 | EXPECT_TRUE(load_timing_info.connect_timing.ssl_start.is_null()); |
| 9830 | EXPECT_TRUE(load_timing_info.connect_timing.ssl_end.is_null()); |
| 9831 | |
| 9832 | EXPECT_EQ(start_time, load_timing_info.connect_timing.connect_start); |
| 9833 | EXPECT_EQ(start_time + 3 * kTimeIncrement, |
| 9834 | load_timing_info.connect_timing.connect_end); |
| 9835 | |
| 9836 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 9837 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 9838 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9839 | |
| 9840 | histograms.ExpectUniqueSample( |
| 9841 | "Net.Proxy.RedirectDuringConnect", |
| 9842 | HttpNetworkTransaction::kMainFrameByExplicitProxy, 1); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9843 | } |
| 9844 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 9845 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9846 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9847 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9848 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9849 | |
| 9850 | HttpRequestInfo request; |
| 9851 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9852 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9853 | request.traffic_annotation = |
| 9854 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9855 | |
| 9856 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9857 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9858 | "Host: www.example.org:443\r\n" |
| 9859 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9860 | }; |
| 9861 | |
| 9862 | MockRead data_reads[] = { |
| 9863 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 9864 | MockRead("Content-Length: 23\r\n\r\n"), |
| 9865 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9866 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9867 | }; |
| 9868 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9869 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9870 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9871 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9872 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9873 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9874 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9875 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9876 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9877 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9878 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9879 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9880 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9881 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9882 | |
| 9883 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9884 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9885 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 9886 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9887 | } |
| 9888 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 9889 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9890 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9891 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9892 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9893 | |
| 9894 | HttpRequestInfo request; |
| 9895 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9896 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9897 | request.traffic_annotation = |
| 9898 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9899 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9900 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9901 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 9902 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9903 | spdy::SpdySerializedFrame rst( |
| 9904 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9905 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9906 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9907 | }; |
| 9908 | |
| 9909 | static const char* const kExtraHeaders[] = { |
| 9910 | "location", |
| 9911 | "http://login.example.com/", |
| 9912 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9913 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9914 | "404", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9915 | spdy::SpdySerializedFrame body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9916 | spdy_util_.ConstructSpdyDataFrame(1, "The host does not exist", true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9917 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9918 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9919 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9920 | }; |
| 9921 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9922 | SequencedSocketData data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9923 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9924 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9925 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9926 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9927 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9928 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9929 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9930 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9931 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9932 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9933 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9934 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9935 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9936 | |
| 9937 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9938 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9939 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 9940 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9941 | } |
| 9942 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9943 | // Test the request-challenge-retry sequence for basic auth, through |
| 9944 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9945 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9946 | HttpRequestInfo request; |
| 9947 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9948 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9949 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 9950 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9951 | request.traffic_annotation = |
| 9952 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9953 | |
| 9954 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9955 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9956 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9957 | "HTTPS myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9958 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9959 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9960 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9961 | |
| 9962 | // Since we have proxy, should try to establish tunnel. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9963 | spdy::SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9964 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 9965 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9966 | spdy::SpdySerializedFrame rst( |
| 9967 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9968 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9969 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9970 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9971 | // be issuing -- the final header line contains the credentials. |
| 9972 | const char* const kAuthCredentials[] = { |
| 9973 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 9974 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9975 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9976 | kAuthCredentials, base::size(kAuthCredentials) / 2, 3, |
| 9977 | HttpProxyConnectJob::kH2QuicTunnelPriority, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9978 | HostPortPair("www.example.org", 443))); |
| 9979 | // fetch https://www.example.org/ via HTTP |
| 9980 | const char get[] = |
| 9981 | "GET / HTTP/1.1\r\n" |
| 9982 | "Host: www.example.org\r\n" |
| 9983 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9984 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9985 | spdy_util_.ConstructSpdyDataFrame(3, get, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9986 | |
| 9987 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9988 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 9989 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9990 | }; |
| 9991 | |
| 9992 | // The proxy responds to the connect with a 407, using a persistent |
| 9993 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 9994 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9995 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9996 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 9997 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9998 | spdy::SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9999 | kAuthStatus, kAuthChallenge, base::size(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10000 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10001 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10002 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10003 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 10004 | "Content-Length: 5\r\n\r\n"; |
| 10005 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10006 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 10007 | spdy_util_.ConstructSpdyDataFrame(3, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10008 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 10009 | spdy_util_.ConstructSpdyDataFrame(3, "hello", false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10010 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10011 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 10012 | CreateMockRead(conn_resp, 4, ASYNC), |
| 10013 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 10014 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10015 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10016 | }; |
| 10017 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10018 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10019 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10020 | // Negotiate SPDY to the proxy |
| 10021 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10022 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10023 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10024 | // Vanilla SSL to the server |
| 10025 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10026 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10027 | |
| 10028 | TestCompletionCallback callback1; |
| 10029 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10030 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10031 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10032 | |
| 10033 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10034 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10035 | |
| 10036 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10037 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 10038 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10039 | log.GetEntries(&entries); |
| 10040 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 10041 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 10042 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10043 | ExpectLogContainsSomewhere( |
| 10044 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 10045 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 10046 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10047 | |
| 10048 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10049 | ASSERT_TRUE(response); |
| 10050 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10051 | EXPECT_EQ(407, response->headers->response_code()); |
| 10052 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10053 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10054 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10055 | |
| 10056 | TestCompletionCallback callback2; |
| 10057 | |
| 10058 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 10059 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10060 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10061 | |
| 10062 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10063 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10064 | |
| 10065 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10066 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10067 | |
| 10068 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10069 | EXPECT_EQ(200, response->headers->response_code()); |
| 10070 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 10071 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10072 | |
| 10073 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10074 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10075 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10076 | LoadTimingInfo load_timing_info; |
| 10077 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10078 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10079 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10080 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10081 | trans.reset(); |
| 10082 | session->CloseAllConnections(); |
| 10083 | } |
| 10084 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10085 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 10086 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10087 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10088 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10089 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10090 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 10091 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10092 | HttpRequestInfo request; |
| 10093 | HttpRequestInfo push_request; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10094 | request.traffic_annotation = |
| 10095 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10096 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10097 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10098 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10099 | push_request.method = "GET"; |
| 10100 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10101 | push_request.traffic_annotation = |
| 10102 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10103 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10104 | // Configure against https proxy server "myproxy:443". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10105 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10106 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10107 | "HTTPS myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10108 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10109 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10110 | |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10111 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10112 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10113 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10114 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10115 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10116 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10117 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10118 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10119 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10120 | |
| 10121 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10122 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10123 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10124 | }; |
| 10125 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10126 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10127 | nullptr, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 10128 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10129 | spdy::SpdySerializedFrame stream1_reply( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10130 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10131 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10132 | spdy::SpdySerializedFrame stream1_body( |
| 10133 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10134 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10135 | spdy::SpdySerializedFrame stream2_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 10136 | spdy_util_.ConstructSpdyDataFrame(2, "pushed", true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10137 | |
| 10138 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 10139 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 10140 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10141 | CreateMockRead(stream1_body, 4, ASYNC), |
| 10142 | CreateMockRead(stream2_body, 5, ASYNC), |
| 10143 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10144 | }; |
| 10145 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10146 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10147 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10148 | // Negotiate SPDY to the proxy |
| 10149 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10150 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10151 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10152 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10153 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10154 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10155 | TestCompletionCallback callback; |
| 10156 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10157 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10158 | |
| 10159 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10160 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10161 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10162 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10163 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10164 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10165 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10166 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10167 | |
| 10168 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10169 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10170 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 10171 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10172 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10173 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10174 | |
| 10175 | EXPECT_EQ(200, response->headers->response_code()); |
| 10176 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10177 | |
| 10178 | std::string response_data; |
| 10179 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10180 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10181 | EXPECT_EQ("hello!", response_data); |
| 10182 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10183 | LoadTimingInfo load_timing_info; |
| 10184 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10185 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10186 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10187 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10188 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10189 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10190 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 10191 | |
| 10192 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10193 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10194 | EXPECT_EQ("pushed", response_data); |
| 10195 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10196 | LoadTimingInfo push_load_timing_info; |
| 10197 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 10198 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 10199 | // The transactions should share a socket ID, despite being for different |
| 10200 | // origins. |
| 10201 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 10202 | push_load_timing_info.socket_log_id); |
| 10203 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10204 | trans.reset(); |
| 10205 | push_trans.reset(); |
| 10206 | session->CloseAllConnections(); |
| 10207 | } |
| 10208 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10209 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10210 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10211 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10212 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10213 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 10214 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10215 | HttpRequestInfo request; |
| 10216 | |
| 10217 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10218 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10219 | request.traffic_annotation = |
| 10220 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10221 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10222 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10223 | "https://myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10224 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10225 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10226 | |
| 10227 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10228 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10229 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10230 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10231 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10232 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10233 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10234 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10235 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10236 | spdy::SpdySerializedFrame push_rst( |
| 10237 | spdy_util_.ConstructSpdyRstStream(2, spdy::ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10238 | |
| 10239 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10240 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10241 | }; |
| 10242 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10243 | spdy::SpdySerializedFrame stream1_reply( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10244 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10245 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10246 | spdy::SpdySerializedFrame stream1_body( |
| 10247 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10248 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10249 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10250 | nullptr, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10251 | |
| 10252 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10253 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10254 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 10255 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 10256 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10257 | }; |
| 10258 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10259 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10260 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10261 | // Negotiate SPDY to the proxy |
| 10262 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10263 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10264 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10265 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10266 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10267 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10268 | TestCompletionCallback callback; |
| 10269 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10270 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10271 | |
| 10272 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10273 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10274 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10275 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10276 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10277 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10278 | |
| 10279 | EXPECT_EQ(200, response->headers->response_code()); |
| 10280 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10281 | |
| 10282 | std::string response_data; |
| 10283 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10284 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10285 | EXPECT_EQ("hello!", response_data); |
| 10286 | |
| 10287 | trans.reset(); |
| 10288 | session->CloseAllConnections(); |
| 10289 | } |
| 10290 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10291 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 10292 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10293 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10294 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10295 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10296 | proxy_delegate->set_trusted_spdy_proxy( |
| 10297 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 10298 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10299 | HttpRequestInfo request; |
| 10300 | |
| 10301 | request.method = "GET"; |
| 10302 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10303 | request.traffic_annotation = |
| 10304 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10305 | |
| 10306 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10307 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10308 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10309 | BoundTestNetLog log; |
| 10310 | session_deps_.net_log = log.bound().net_log(); |
| 10311 | |
| 10312 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10313 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10314 | proxy_delegate.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10315 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10316 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10317 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10318 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10319 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10320 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10321 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10322 | |
| 10323 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10324 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10325 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10326 | }; |
| 10327 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10328 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10329 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10330 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10331 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 10332 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 10333 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10334 | spdy::SpdySerializedFrame stream1_body( |
| 10335 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10336 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10337 | spdy::SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10338 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10339 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10340 | spdy::SpdySerializedFrame stream2_body( |
| 10341 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10342 | |
| 10343 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10344 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10345 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10346 | CreateMockRead(stream1_body, 4, ASYNC), |
| 10347 | CreateMockRead(stream2_body, 5, ASYNC), |
| 10348 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10349 | }; |
| 10350 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10351 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10352 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 10353 | // Negotiate SPDY to the proxy |
| 10354 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10355 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10356 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 10357 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10358 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10359 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10360 | TestCompletionCallback callback; |
| 10361 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10362 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10363 | |
| 10364 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10365 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10366 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10367 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10368 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10369 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10370 | |
| 10371 | EXPECT_EQ(200, response->headers->response_code()); |
| 10372 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10373 | |
| 10374 | std::string response_data; |
| 10375 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10376 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10377 | EXPECT_EQ("hello!", response_data); |
| 10378 | |
| 10379 | trans.reset(); |
| 10380 | session->CloseAllConnections(); |
| 10381 | } |
| 10382 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10383 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 10384 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10385 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10386 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10387 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10388 | |
| 10389 | HttpRequestInfo request; |
| 10390 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10391 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10392 | request.traffic_annotation = |
| 10393 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10394 | |
| 10395 | // Attempt to fetch the URL from a server with a bad cert |
| 10396 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10397 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10398 | "Host: www.example.org:443\r\n" |
| 10399 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10400 | }; |
| 10401 | |
| 10402 | MockRead bad_cert_reads[] = { |
| 10403 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10404 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10405 | }; |
| 10406 | |
| 10407 | // Attempt to fetch the URL with a good cert |
| 10408 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10409 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10410 | "Host: www.example.org:443\r\n" |
| 10411 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10412 | MockWrite("GET / HTTP/1.1\r\n" |
| 10413 | "Host: www.example.org\r\n" |
| 10414 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10415 | }; |
| 10416 | |
| 10417 | MockRead good_cert_reads[] = { |
| 10418 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 10419 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10420 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10421 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10422 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10423 | }; |
| 10424 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10425 | StaticSocketDataProvider ssl_bad_certificate(bad_cert_reads, bad_cert_writes); |
| 10426 | StaticSocketDataProvider data(good_cert_reads, good_data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10427 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 10428 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10429 | |
| 10430 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10431 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10432 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 10433 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10434 | |
| 10435 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10436 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10437 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10438 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10439 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10440 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10441 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10442 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10443 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10444 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10445 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10446 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10447 | |
| 10448 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10449 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10450 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10451 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10452 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10453 | |
| 10454 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10455 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10456 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10457 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10458 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10459 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10460 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10461 | } |
| 10462 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10463 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10464 | HttpRequestInfo request; |
| 10465 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10466 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10467 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10468 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10469 | request.traffic_annotation = |
| 10470 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10471 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10472 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10473 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10474 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10475 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10476 | MockWrite( |
| 10477 | "GET / HTTP/1.1\r\n" |
| 10478 | "Host: www.example.org\r\n" |
| 10479 | "Connection: keep-alive\r\n" |
| 10480 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10481 | }; |
| 10482 | |
| 10483 | // Lastly, the server responds with the actual content. |
| 10484 | MockRead data_reads[] = { |
| 10485 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10486 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10487 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10488 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10489 | }; |
| 10490 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10491 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10492 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10493 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10494 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10495 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10496 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10497 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10498 | |
| 10499 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10500 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10501 | } |
| 10502 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10503 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10504 | // Test user agent values, used both for the request header of the original |
| 10505 | // request, and the value returned by the HttpUserAgentSettings. nullptr means |
| 10506 | // no request header / no HttpUserAgentSettings object. |
| 10507 | const char* kTestUserAgents[] = {nullptr, "", "Foopy"}; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10508 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10509 | for (const char* setting_user_agent : kTestUserAgents) { |
| 10510 | if (!setting_user_agent) { |
| 10511 | session_deps_.http_user_agent_settings.reset(); |
| 10512 | } else { |
| 10513 | session_deps_.http_user_agent_settings = |
| 10514 | std::make_unique<StaticHttpUserAgentSettings>( |
| 10515 | std::string() /* accept-language */, setting_user_agent); |
| 10516 | } |
| 10517 | session_deps_.proxy_resolution_service = |
| 10518 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 10519 | TRAFFIC_ANNOTATION_FOR_TESTS); |
| 10520 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10521 | for (const char* request_user_agent : kTestUserAgents) { |
| 10522 | HttpRequestInfo request; |
| 10523 | request.method = "GET"; |
| 10524 | request.url = GURL("https://www.example.org/"); |
| 10525 | if (request_user_agent) { |
| 10526 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10527 | request_user_agent); |
| 10528 | } |
| 10529 | request.traffic_annotation = |
| 10530 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10531 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10532 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10533 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10534 | std::string expected_request; |
| 10535 | if (!setting_user_agent || strlen(setting_user_agent) == 0) { |
| 10536 | expected_request = |
| 10537 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10538 | "Host: www.example.org:443\r\n" |
| 10539 | "Proxy-Connection: keep-alive\r\n\r\n"; |
| 10540 | } else { |
| 10541 | expected_request = base::StringPrintf( |
| 10542 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10543 | "Host: www.example.org:443\r\n" |
| 10544 | "Proxy-Connection: keep-alive\r\n" |
| 10545 | "User-Agent: %s\r\n\r\n", |
| 10546 | setting_user_agent); |
| 10547 | } |
| 10548 | MockWrite data_writes[] = { |
| 10549 | MockWrite(expected_request.c_str()), |
| 10550 | }; |
| 10551 | MockRead data_reads[] = { |
| 10552 | // Return an error, so the transaction stops here (this test isn't |
| 10553 | // interested in the rest). |
| 10554 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 10555 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10556 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 10557 | }; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10558 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10559 | StaticSocketDataProvider data(data_reads, data_writes); |
| 10560 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10561 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10562 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10563 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10564 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 10565 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10566 | |
| 10567 | rv = callback.WaitForResult(); |
| 10568 | EXPECT_THAT(rv, IsOk()); |
| 10569 | } |
| 10570 | } |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10571 | } |
| 10572 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10573 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10574 | HttpRequestInfo request; |
| 10575 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10576 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 10577 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 10578 | "http://the.previous.site.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10579 | request.traffic_annotation = |
| 10580 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10581 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10582 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10583 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10584 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10585 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10586 | MockWrite( |
| 10587 | "GET / HTTP/1.1\r\n" |
| 10588 | "Host: www.example.org\r\n" |
| 10589 | "Connection: keep-alive\r\n" |
| 10590 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10591 | }; |
| 10592 | |
| 10593 | // Lastly, the server responds with the actual content. |
| 10594 | MockRead data_reads[] = { |
| 10595 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10596 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10597 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10598 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10599 | }; |
| 10600 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10601 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10602 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10603 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10604 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10605 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10606 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10607 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10608 | |
| 10609 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10610 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10611 | } |
| 10612 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10613 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10614 | HttpRequestInfo request; |
| 10615 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10616 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10617 | request.traffic_annotation = |
| 10618 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10619 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10620 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10621 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10622 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10623 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10624 | MockWrite( |
| 10625 | "POST / HTTP/1.1\r\n" |
| 10626 | "Host: www.example.org\r\n" |
| 10627 | "Connection: keep-alive\r\n" |
| 10628 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10629 | }; |
| 10630 | |
| 10631 | // Lastly, the server responds with the actual content. |
| 10632 | MockRead data_reads[] = { |
| 10633 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10634 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10635 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10636 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10637 | }; |
| 10638 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10639 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10640 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10641 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10642 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10643 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10644 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10645 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10646 | |
| 10647 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10648 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10649 | } |
| 10650 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10651 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10652 | HttpRequestInfo request; |
| 10653 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10654 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10655 | request.traffic_annotation = |
| 10656 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10657 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10658 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10659 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10660 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10661 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10662 | MockWrite( |
| 10663 | "PUT / HTTP/1.1\r\n" |
| 10664 | "Host: www.example.org\r\n" |
| 10665 | "Connection: keep-alive\r\n" |
| 10666 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10667 | }; |
| 10668 | |
| 10669 | // Lastly, the server responds with the actual content. |
| 10670 | MockRead data_reads[] = { |
| 10671 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10672 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10673 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10674 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10675 | }; |
| 10676 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10677 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10678 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10679 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10680 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10681 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10682 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10683 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10684 | |
| 10685 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10686 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10687 | } |
| 10688 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10689 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10690 | HttpRequestInfo request; |
| 10691 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10692 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10693 | request.traffic_annotation = |
| 10694 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10695 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10696 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10697 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10698 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10699 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 10700 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 10701 | "Host: www.example.org\r\n" |
| 10702 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10703 | }; |
| 10704 | |
| 10705 | // Lastly, the server responds with the actual content. |
| 10706 | MockRead data_reads[] = { |
| 10707 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10708 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10709 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10710 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10711 | }; |
| 10712 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10713 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10714 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10715 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10716 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10717 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10718 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10719 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10720 | |
| 10721 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10722 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10723 | } |
| 10724 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10725 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10726 | HttpRequestInfo request; |
| 10727 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10728 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10729 | request.load_flags = LOAD_BYPASS_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10730 | request.traffic_annotation = |
| 10731 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10732 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10733 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10734 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10735 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10736 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10737 | MockWrite( |
| 10738 | "GET / HTTP/1.1\r\n" |
| 10739 | "Host: www.example.org\r\n" |
| 10740 | "Connection: keep-alive\r\n" |
| 10741 | "Pragma: no-cache\r\n" |
| 10742 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10743 | }; |
| 10744 | |
| 10745 | // Lastly, the server responds with the actual content. |
| 10746 | MockRead data_reads[] = { |
| 10747 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10748 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10749 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10750 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10751 | }; |
| 10752 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10753 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10754 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10755 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10756 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10757 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10758 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10759 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10760 | |
| 10761 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10762 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10763 | } |
| 10764 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10765 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10766 | HttpRequestInfo request; |
| 10767 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10768 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10769 | request.load_flags = LOAD_VALIDATE_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10770 | request.traffic_annotation = |
| 10771 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10772 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10773 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10774 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10775 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10776 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10777 | MockWrite( |
| 10778 | "GET / HTTP/1.1\r\n" |
| 10779 | "Host: www.example.org\r\n" |
| 10780 | "Connection: keep-alive\r\n" |
| 10781 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10782 | }; |
| 10783 | |
| 10784 | // Lastly, the server responds with the actual content. |
| 10785 | MockRead data_reads[] = { |
| 10786 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10787 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10788 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10789 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10790 | }; |
| 10791 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10792 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10793 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10794 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10795 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10796 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10797 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10798 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10799 | |
| 10800 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10801 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10802 | } |
| 10803 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10804 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10805 | HttpRequestInfo request; |
| 10806 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10807 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10808 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10809 | request.traffic_annotation = |
| 10810 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10811 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10812 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10813 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10814 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10815 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10816 | MockWrite( |
| 10817 | "GET / HTTP/1.1\r\n" |
| 10818 | "Host: www.example.org\r\n" |
| 10819 | "Connection: keep-alive\r\n" |
| 10820 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10821 | }; |
| 10822 | |
| 10823 | // Lastly, the server responds with the actual content. |
| 10824 | MockRead data_reads[] = { |
| 10825 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10826 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10827 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10828 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10829 | }; |
| 10830 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10831 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10832 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10833 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10834 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10835 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10836 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10837 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10838 | |
| 10839 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10840 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10841 | } |
| 10842 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10843 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10844 | HttpRequestInfo request; |
| 10845 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10846 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10847 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 10848 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 10849 | request.extra_headers.SetHeader("FoO", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10850 | request.traffic_annotation = |
| 10851 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10852 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10853 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10854 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10855 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10856 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10857 | MockWrite( |
| 10858 | "GET / HTTP/1.1\r\n" |
| 10859 | "Host: www.example.org\r\n" |
| 10860 | "Connection: keep-alive\r\n" |
| 10861 | "referer: www.foo.com\r\n" |
| 10862 | "hEllo: Kitty\r\n" |
| 10863 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10864 | }; |
| 10865 | |
| 10866 | // Lastly, the server responds with the actual content. |
| 10867 | MockRead data_reads[] = { |
| 10868 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10869 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10870 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10871 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10872 | }; |
| 10873 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10874 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10875 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10876 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10877 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10878 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10879 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10880 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10881 | |
| 10882 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10883 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10884 | } |
| 10885 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10886 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10887 | HttpRequestInfo request; |
| 10888 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10889 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10890 | request.traffic_annotation = |
| 10891 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10892 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10893 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10894 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10895 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10896 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10897 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10898 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10899 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10900 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10901 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10902 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 10903 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10904 | |
| 10905 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10906 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 10907 | MockWrite("GET / HTTP/1.1\r\n" |
| 10908 | "Host: www.example.org\r\n" |
| 10909 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10910 | |
| 10911 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10912 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 10913 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10914 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10915 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10916 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10917 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10918 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10919 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10920 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10921 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10922 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10923 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10924 | |
| 10925 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10926 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10927 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10928 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10929 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10930 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10931 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10932 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10933 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10934 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10935 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10936 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10937 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10938 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10939 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10940 | EXPECT_EQ("Payload", response_text); |
| 10941 | } |
| 10942 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10943 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10944 | HttpRequestInfo request; |
| 10945 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10946 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10947 | request.traffic_annotation = |
| 10948 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10949 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10950 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10951 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10952 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10953 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10954 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10955 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10956 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10957 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10958 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10959 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 10960 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10961 | |
| 10962 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10963 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10964 | base::size(write_buffer)), |
| 10965 | MockWrite("GET / HTTP/1.1\r\n" |
| 10966 | "Host: www.example.org\r\n" |
| 10967 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10968 | |
| 10969 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10970 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 10971 | base::size(read_buffer)), |
| 10972 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10973 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10974 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10975 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10976 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10977 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10978 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10979 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10980 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10981 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10982 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10983 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10984 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10985 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10986 | |
| 10987 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10988 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10989 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10990 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10991 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10992 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10993 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10994 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10995 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10996 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10997 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10998 | |
| 10999 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11000 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11001 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11002 | EXPECT_EQ("Payload", response_text); |
| 11003 | } |
| 11004 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11005 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11006 | HttpRequestInfo request; |
| 11007 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11008 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11009 | request.traffic_annotation = |
| 11010 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11011 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11012 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11013 | "socks4://myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11014 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11015 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11016 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11017 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11018 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11019 | |
| 11020 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 11021 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 11022 | |
| 11023 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11024 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 11025 | MockWrite("GET / HTTP/1.1\r\n" |
| 11026 | "Host: www.example.org\r\n" |
| 11027 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11028 | |
| 11029 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11030 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 11031 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11032 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11033 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [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] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11037 | |
| 11038 | TestCompletionCallback callback; |
| 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] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11042 | |
| 11043 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11044 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [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); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11048 | |
| 11049 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11050 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11051 | TestLoadTimingNotReused(load_timing_info, |
| 11052 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 11053 | |
| 11054 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11055 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11056 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11057 | EXPECT_EQ("Payload", response_text); |
| 11058 | } |
| 11059 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11060 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11061 | HttpRequestInfo request; |
| 11062 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11063 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11064 | request.traffic_annotation = |
| 11065 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11066 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11067 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11068 | ProxyResolutionService::CreateFixedFromPacResult( |
| 11069 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11070 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11071 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11072 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11073 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11074 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11075 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11076 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 11077 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11078 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11079 | 0x05, // Version |
| 11080 | 0x01, // Command (CONNECT) |
| 11081 | 0x00, // Reserved. |
| 11082 | 0x03, // Address type (DOMAINNAME). |
| 11083 | 0x0F, // Length of domain (15) |
| 11084 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 11085 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11086 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11087 | const char kSOCKS5OkResponse[] = |
| 11088 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 11089 | |
| 11090 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11091 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
| 11092 | MockWrite(ASYNC, kSOCKS5OkRequest, base::size(kSOCKS5OkRequest)), |
| 11093 | MockWrite("GET / HTTP/1.1\r\n" |
| 11094 | "Host: www.example.org\r\n" |
| 11095 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11096 | |
| 11097 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11098 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 11099 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 11100 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11101 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11102 | MockRead("Payload"), |
| 11103 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11104 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11105 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11106 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11107 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11108 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11109 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11110 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11111 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11112 | |
| 11113 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11114 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11115 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11116 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11117 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11118 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11119 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11120 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11121 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11122 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11123 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 11124 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11125 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11126 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11127 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11128 | EXPECT_EQ("Payload", response_text); |
| 11129 | } |
| 11130 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11131 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11132 | HttpRequestInfo request; |
| 11133 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11134 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11135 | request.traffic_annotation = |
| 11136 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11137 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11138 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11139 | ProxyResolutionService::CreateFixedFromPacResult( |
| 11140 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11141 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11142 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11143 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11144 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11145 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11146 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11147 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 11148 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11149 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11150 | 0x05, // Version |
| 11151 | 0x01, // Command (CONNECT) |
| 11152 | 0x00, // Reserved. |
| 11153 | 0x03, // Address type (DOMAINNAME). |
| 11154 | 0x0F, // Length of domain (15) |
| 11155 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 11156 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11157 | }; |
| 11158 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11159 | const char kSOCKS5OkResponse[] = |
| 11160 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 11161 | |
| 11162 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11163 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11164 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11165 | base::size(kSOCKS5OkRequest)), |
| 11166 | MockWrite("GET / HTTP/1.1\r\n" |
| 11167 | "Host: www.example.org\r\n" |
| 11168 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11169 | |
| 11170 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11171 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 11172 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 11173 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11174 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11175 | MockRead("Payload"), |
| 11176 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11177 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11178 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11179 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11180 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11181 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11182 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11183 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11184 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11185 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11186 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11187 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11188 | |
| 11189 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11190 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11191 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11192 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11193 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11194 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11195 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11196 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11197 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11198 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11199 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 11200 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11201 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11202 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11203 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11204 | EXPECT_EQ("Payload", response_text); |
| 11205 | } |
| 11206 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11207 | namespace { |
| 11208 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11209 | // Tests that for connection endpoints the group ids are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11210 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11211 | struct GroupIdTest { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11212 | std::string proxy_server; |
| 11213 | std::string url; |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11214 | ClientSocketPool::GroupId expected_group_id; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 11215 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11216 | }; |
| 11217 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11218 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupIdTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11219 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11220 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11221 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11222 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11223 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11224 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11225 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11226 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 11227 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11228 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11229 | |
| 11230 | return session; |
| 11231 | } |
| 11232 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11233 | int GroupIdTransactionHelper(const std::string& url, |
| 11234 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11235 | HttpRequestInfo request; |
| 11236 | request.method = "GET"; |
| 11237 | request.url = GURL(url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11238 | request.traffic_annotation = |
| 11239 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11240 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11241 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11242 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11243 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11244 | |
| 11245 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11246 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11247 | } |
| 11248 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11249 | } // namespace |
| 11250 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11251 | TEST_F(HttpNetworkTransactionTest, GroupIdForDirectConnections) { |
| 11252 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11253 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11254 | "", // unused |
| 11255 | "http://www.example.org/direct", |
| 11256 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11257 | ClientSocketPool::SocketType::kHttp, |
| 11258 | false /* privacy_mode */), |
| 11259 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11260 | }, |
| 11261 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11262 | "", // unused |
| 11263 | "http://[2001:1418:13:1::25]/direct", |
| 11264 | ClientSocketPool::GroupId(HostPortPair("2001:1418:13:1::25", 80), |
| 11265 | ClientSocketPool::SocketType::kHttp, |
| 11266 | false /* privacy_mode */), |
| 11267 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11268 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11269 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11270 | // SSL Tests |
| 11271 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11272 | "", // unused |
| 11273 | "https://www.example.org/direct_ssl", |
| 11274 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11275 | ClientSocketPool::SocketType::kSsl, |
| 11276 | false /* privacy_mode */), |
| 11277 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11278 | }, |
| 11279 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11280 | "", // unused |
| 11281 | "https://[2001:1418:13:1::25]/direct", |
| 11282 | ClientSocketPool::GroupId(HostPortPair("2001:1418:13:1::25", 443), |
| 11283 | ClientSocketPool::SocketType::kSsl, |
| 11284 | false /* privacy_mode */), |
| 11285 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11286 | }, |
| 11287 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11288 | "", // unused |
| 11289 | "https://host.with.alternate/direct", |
| 11290 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11291 | ClientSocketPool::SocketType::kSsl, |
| 11292 | false /* privacy_mode */), |
| 11293 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11294 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11295 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11296 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11297 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11298 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11299 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11300 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11301 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11302 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11303 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11304 | HttpNetworkSessionPeer peer(session.get()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11305 | CaptureGroupIdTransportSocketPool* transport_conn_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 11306 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11307 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11308 | mock_pool_manager->SetSocketPool(ProxyServer::Direct(), |
| 11309 | base::WrapUnique(transport_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11310 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11311 | |
| 11312 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11313 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11314 | EXPECT_EQ(tests[i].expected_group_id, |
| 11315 | transport_conn_pool->last_group_id_received()); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 11316 | EXPECT_TRUE(transport_conn_pool->socket_requested()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11317 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11318 | } |
| 11319 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11320 | TEST_F(HttpNetworkTransactionTest, GroupIdForHTTPProxyConnections) { |
| 11321 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11322 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11323 | "http_proxy", |
| 11324 | "http://www.example.org/http_proxy_normal", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11325 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11326 | ClientSocketPool::SocketType::kHttp, |
| 11327 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11328 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11329 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11330 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11331 | // SSL Tests |
| 11332 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11333 | "http_proxy", |
| 11334 | "https://www.example.org/http_connect_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11335 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11336 | ClientSocketPool::SocketType::kSsl, |
| 11337 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11338 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11339 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11340 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11341 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11342 | "http_proxy", |
| 11343 | "https://host.with.alternate/direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11344 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11345 | ClientSocketPool::SocketType::kSsl, |
| 11346 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11347 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11348 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 11349 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11350 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11351 | "http_proxy", |
| 11352 | "ftp://ftp.google.com/http_proxy_normal", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11353 | ClientSocketPool::GroupId(HostPortPair("ftp.google.com", 21), |
| 11354 | ClientSocketPool::SocketType::kFtp, |
| 11355 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11356 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11357 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11358 | }; |
| 11359 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11360 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11361 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11362 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11363 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11364 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11365 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11366 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11367 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11368 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11369 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11370 | HostPortPair("http_proxy", 80)); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11371 | CaptureGroupIdTransportSocketPool* http_proxy_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 11372 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11373 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11374 | mock_pool_manager->SetSocketPool(proxy_server, |
| 11375 | base::WrapUnique(http_proxy_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11376 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11377 | |
| 11378 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11379 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11380 | EXPECT_EQ(tests[i].expected_group_id, |
| 11381 | http_proxy_pool->last_group_id_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11382 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11383 | } |
| 11384 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11385 | TEST_F(HttpNetworkTransactionTest, GroupIdForSOCKSConnections) { |
| 11386 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11387 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11388 | "socks4://socks_proxy:1080", |
| 11389 | "http://www.example.org/socks4_direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11390 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11391 | ClientSocketPool::SocketType::kHttp, |
| 11392 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11393 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11394 | }, |
| 11395 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11396 | "socks5://socks_proxy:1080", |
| 11397 | "http://www.example.org/socks5_direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11398 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11399 | ClientSocketPool::SocketType::kHttp, |
| 11400 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11401 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11402 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11403 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11404 | // SSL Tests |
| 11405 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11406 | "socks4://socks_proxy:1080", |
| 11407 | "https://www.example.org/socks4_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11408 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11409 | ClientSocketPool::SocketType::kSsl, |
| 11410 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11411 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11412 | }, |
| 11413 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11414 | "socks5://socks_proxy:1080", |
| 11415 | "https://www.example.org/socks5_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11416 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11417 | ClientSocketPool::SocketType::kSsl, |
| 11418 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11419 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11420 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11421 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11422 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11423 | "socks4://socks_proxy:1080", |
| 11424 | "https://host.with.alternate/direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11425 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11426 | ClientSocketPool::SocketType::kSsl, |
| 11427 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11428 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11429 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11430 | }; |
| 11431 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11432 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11433 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11434 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11435 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11436 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11437 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 11438 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11439 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11440 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11441 | ProxyServer proxy_server( |
| 11442 | ProxyServer::FromURI(tests[i].proxy_server, ProxyServer::SCHEME_HTTP)); |
| 11443 | ASSERT_TRUE(proxy_server.is_valid()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11444 | CaptureGroupIdTransportSocketPool* socks_conn_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 11445 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11446 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11447 | mock_pool_manager->SetSocketPool(proxy_server, |
| 11448 | base::WrapUnique(socks_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11449 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11450 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11451 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11452 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11453 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11454 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11455 | EXPECT_EQ(tests[i].expected_group_id, |
| 11456 | socks_conn_pool->last_group_id_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11457 | } |
| 11458 | } |
| 11459 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11460 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11461 | HttpRequestInfo request; |
| 11462 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11463 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11464 | request.traffic_annotation = |
| 11465 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11466 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11467 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11468 | "myproxy:70;foobar:80", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11469 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 11470 | // This simulates failure resolving all hostnames; that means we will fail |
| 11471 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11472 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11473 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11474 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11475 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11476 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11477 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11478 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11479 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11480 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11481 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11482 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11483 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11484 | } |
| 11485 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11486 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11487 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11488 | HttpRequestInfo request; |
| 11489 | request.method = "GET"; |
| 11490 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11491 | request.traffic_annotation = |
| 11492 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11493 | |
| 11494 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11495 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11496 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11497 | StaticSocketDataProvider data(base::span<MockRead>(), write_failure); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11498 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11499 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11500 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11501 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11502 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11503 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11504 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11505 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11506 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11507 | |
| 11508 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11509 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11510 | |
| 11511 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11512 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11513 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11514 | } |
| 11515 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11516 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11517 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11518 | HttpRequestInfo request; |
| 11519 | request.method = "GET"; |
| 11520 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11521 | request.traffic_annotation = |
| 11522 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11523 | |
| 11524 | MockRead data_reads[] = { |
| 11525 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11526 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11527 | }; |
| 11528 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11529 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11530 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11531 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11532 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11533 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11534 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11535 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11536 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11537 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11538 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11539 | |
| 11540 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11541 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11542 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11543 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11544 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11545 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11546 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11547 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11548 | |
| 11549 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11550 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11551 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11552 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11553 | |
| 11554 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11555 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11556 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11557 | } |
| 11558 | |
| 11559 | // Make sure that a dropped connection while draining the body for auth |
| 11560 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11561 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11562 | HttpRequestInfo request; |
| 11563 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11564 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11565 | request.traffic_annotation = |
| 11566 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11567 | |
| 11568 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11569 | MockWrite( |
| 11570 | "GET / HTTP/1.1\r\n" |
| 11571 | "Host: www.example.org\r\n" |
| 11572 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11573 | }; |
| 11574 | |
| 11575 | MockRead data_reads1[] = { |
| 11576 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 11577 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 11578 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11579 | MockRead("Content-Length: 14\r\n\r\n"), |
| 11580 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11581 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11582 | }; |
| 11583 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11584 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11585 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11586 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11587 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11588 | // be issuing -- the final header line contains the credentials. |
| 11589 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11590 | MockWrite( |
| 11591 | "GET / HTTP/1.1\r\n" |
| 11592 | "Host: www.example.org\r\n" |
| 11593 | "Connection: keep-alive\r\n" |
| 11594 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11595 | }; |
| 11596 | |
| 11597 | // Lastly, the server responds with the actual content. |
| 11598 | MockRead data_reads2[] = { |
| 11599 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11600 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11601 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11602 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11603 | }; |
| 11604 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11605 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11606 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11607 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11608 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11609 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11610 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11611 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11612 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11613 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11614 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11615 | |
| 11616 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11617 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11618 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11619 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11620 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11621 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11622 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11623 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11624 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11625 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11626 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11627 | |
| 11628 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11629 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11630 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11631 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11632 | ASSERT_TRUE(response); |
| 11633 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11634 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11635 | } |
| 11636 | |
| 11637 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11638 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11639 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11640 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11641 | |
| 11642 | HttpRequestInfo request; |
| 11643 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11644 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11645 | request.traffic_annotation = |
| 11646 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11647 | |
| 11648 | MockRead proxy_reads[] = { |
| 11649 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11650 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11651 | }; |
| 11652 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11653 | StaticSocketDataProvider data(proxy_reads, base::span<MockWrite>()); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11654 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11655 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11656 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11657 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11658 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11659 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11660 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11661 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11662 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11663 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11664 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11665 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11666 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11667 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11668 | |
| 11669 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11670 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11671 | } |
| 11672 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11673 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11674 | HttpRequestInfo request; |
| 11675 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11676 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11677 | request.traffic_annotation = |
| 11678 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11679 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11680 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11681 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11682 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11683 | MockRead data_reads[] = { |
| 11684 | 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] | 11685 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11686 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11687 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11688 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11689 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11690 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11691 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11692 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11693 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11694 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11695 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11696 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11697 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11698 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11699 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11700 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11701 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11702 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11703 | |
| 11704 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11705 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11706 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11707 | } |
| 11708 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11709 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11710 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11711 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11712 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 11713 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 11714 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11715 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11716 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11717 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11718 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11719 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11720 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11721 | |
| 11722 | HttpRequestInfo request; |
| 11723 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11724 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11725 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11726 | request.traffic_annotation = |
| 11727 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11728 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11729 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11730 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11731 | |
| 11732 | MockRead data_reads[] = { |
| 11733 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 11734 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11735 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11736 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11737 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11738 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11739 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11740 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11741 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11742 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11743 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11744 | |
| 11745 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11746 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11747 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11748 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11749 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11750 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 11751 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11752 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11753 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11754 | } |
| 11755 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11756 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11757 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11758 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11759 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 11760 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 11761 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 11762 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 11763 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11764 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11765 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11766 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11767 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11768 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11769 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11770 | |
| 11771 | HttpRequestInfo request; |
| 11772 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11773 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11774 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11775 | request.traffic_annotation = |
| 11776 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11777 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 11778 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11779 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11780 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11781 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11782 | StaticSocketDataProvider data; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11783 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11784 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11785 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11786 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11787 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11788 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11789 | |
| 11790 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11791 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11792 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11793 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11794 | } |
| 11795 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11796 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11797 | class FakeUploadElementReader : public UploadElementReader { |
| 11798 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 11799 | FakeUploadElementReader() = default; |
| 11800 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11801 | |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11802 | CompletionOnceCallback TakeCallback() { return std::move(callback_); } |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11803 | |
| 11804 | // UploadElementReader overrides: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11805 | int Init(CompletionOnceCallback callback) override { |
| 11806 | callback_ = std::move(callback); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11807 | return ERR_IO_PENDING; |
| 11808 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11809 | uint64_t GetContentLength() const override { return 0; } |
| 11810 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11811 | int Read(IOBuffer* buf, |
| 11812 | int buf_length, |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11813 | CompletionOnceCallback callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11814 | return ERR_FAILED; |
| 11815 | } |
| 11816 | |
| 11817 | private: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11818 | CompletionOnceCallback callback_; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11819 | }; |
| 11820 | |
| 11821 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11822 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 11823 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11824 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11825 | |
| 11826 | HttpRequestInfo request; |
| 11827 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11828 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11829 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11830 | request.traffic_annotation = |
| 11831 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11832 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11833 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11834 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11835 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11836 | |
| 11837 | StaticSocketDataProvider data; |
| 11838 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11839 | |
| 11840 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11841 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11842 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 11843 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11844 | |
| 11845 | // Transaction is pending on request body initialization. |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11846 | CompletionOnceCallback init_callback = fake_reader->TakeCallback(); |
| 11847 | ASSERT_FALSE(init_callback.is_null()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11848 | |
| 11849 | // Return Init()'s result after the transaction gets destroyed. |
| 11850 | trans.reset(); |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11851 | std::move(init_callback).Run(OK); // Should not crash. |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11852 | } |
| 11853 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11854 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11855 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11856 | HttpRequestInfo request; |
| 11857 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11858 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11859 | request.traffic_annotation = |
| 11860 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11861 | |
| 11862 | // First transaction will request a resource and receive a Basic challenge |
| 11863 | // with realm="first_realm". |
| 11864 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11865 | MockWrite( |
| 11866 | "GET / HTTP/1.1\r\n" |
| 11867 | "Host: www.example.org\r\n" |
| 11868 | "Connection: keep-alive\r\n" |
| 11869 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11870 | }; |
| 11871 | MockRead data_reads1[] = { |
| 11872 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11873 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 11874 | "\r\n"), |
| 11875 | }; |
| 11876 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11877 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11878 | // for first_realm. The server will reject and provide a challenge with |
| 11879 | // second_realm. |
| 11880 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11881 | MockWrite( |
| 11882 | "GET / HTTP/1.1\r\n" |
| 11883 | "Host: www.example.org\r\n" |
| 11884 | "Connection: keep-alive\r\n" |
| 11885 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 11886 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11887 | }; |
| 11888 | MockRead data_reads2[] = { |
| 11889 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11890 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 11891 | "\r\n"), |
| 11892 | }; |
| 11893 | |
| 11894 | // This again fails, and goes back to first_realm. Make sure that the |
| 11895 | // entry is removed from cache. |
| 11896 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11897 | MockWrite( |
| 11898 | "GET / HTTP/1.1\r\n" |
| 11899 | "Host: www.example.org\r\n" |
| 11900 | "Connection: keep-alive\r\n" |
| 11901 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 11902 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11903 | }; |
| 11904 | MockRead data_reads3[] = { |
| 11905 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11906 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 11907 | "\r\n"), |
| 11908 | }; |
| 11909 | |
| 11910 | // Try one last time (with the correct password) and get the resource. |
| 11911 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11912 | MockWrite( |
| 11913 | "GET / HTTP/1.1\r\n" |
| 11914 | "Host: www.example.org\r\n" |
| 11915 | "Connection: keep-alive\r\n" |
| 11916 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 11917 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11918 | }; |
| 11919 | MockRead data_reads4[] = { |
| 11920 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11921 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11922 | "Content-Length: 5\r\n" |
| 11923 | "\r\n" |
| 11924 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11925 | }; |
| 11926 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11927 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 11928 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 11929 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
| 11930 | StaticSocketDataProvider data4(data_reads4, data_writes4); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11931 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 11932 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 11933 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 11934 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11935 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11936 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11937 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11938 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11939 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11940 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11941 | // Issue the first request with Authorize headers. There should be a |
| 11942 | // password prompt for first_realm waiting to be filled in after the |
| 11943 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11944 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11945 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11946 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11947 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11948 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11949 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11950 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11951 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11952 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11953 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11954 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11955 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11956 | |
| 11957 | // Issue the second request with an incorrect password. There should be a |
| 11958 | // password prompt for second_realm waiting to be filled in after the |
| 11959 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11960 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11961 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 11962 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11963 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11964 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11965 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11966 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11967 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11968 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11969 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11970 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11971 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11972 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11973 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11974 | |
| 11975 | // Issue the third request with another incorrect password. There should be |
| 11976 | // a password prompt for first_realm waiting to be filled in. If the password |
| 11977 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 11978 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11979 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11980 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 11981 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11982 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11983 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11984 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11985 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11986 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11987 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11988 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11989 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11990 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11991 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11992 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11993 | |
| 11994 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11995 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11996 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 11997 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11998 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11999 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12000 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12001 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12002 | ASSERT_TRUE(response); |
| 12003 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12004 | } |
| 12005 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12006 | // Regression test for https://crbug.com/754395. |
| 12007 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 12008 | MockRead data_reads[] = { |
| 12009 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12010 | MockRead(kAlternativeServiceHttpHeader), |
| 12011 | MockRead("\r\n"), |
| 12012 | MockRead("hello world"), |
| 12013 | MockRead(SYNCHRONOUS, OK), |
| 12014 | }; |
| 12015 | |
| 12016 | HttpRequestInfo request; |
| 12017 | request.method = "GET"; |
| 12018 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12019 | request.traffic_annotation = |
| 12020 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12021 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12022 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12023 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12024 | |
| 12025 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12026 | ssl.ssl_info.cert = |
| 12027 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12028 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 12029 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12030 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12031 | |
| 12032 | TestCompletionCallback callback; |
| 12033 | |
| 12034 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12035 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12036 | |
| 12037 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 12038 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12039 | |
| 12040 | url::SchemeHostPort test_server(request.url); |
| 12041 | HttpServerProperties* http_server_properties = |
| 12042 | session->http_server_properties(); |
| 12043 | EXPECT_TRUE( |
| 12044 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 12045 | |
| 12046 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 12047 | |
| 12048 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 12049 | ASSERT_TRUE(response); |
| 12050 | ASSERT_TRUE(response->headers); |
| 12051 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12052 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 12053 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 12054 | |
| 12055 | std::string response_data; |
| 12056 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 12057 | EXPECT_EQ("hello world", response_data); |
| 12058 | |
| 12059 | EXPECT_TRUE( |
| 12060 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 12061 | } |
| 12062 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12063 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12064 | MockRead data_reads[] = { |
| 12065 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12066 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12067 | MockRead("\r\n"), |
| 12068 | MockRead("hello world"), |
| 12069 | MockRead(SYNCHRONOUS, OK), |
| 12070 | }; |
| 12071 | |
| 12072 | HttpRequestInfo request; |
| 12073 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12074 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12075 | request.traffic_annotation = |
| 12076 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12077 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12078 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12079 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12080 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12081 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12082 | ssl.ssl_info.cert = |
| 12083 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12084 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12085 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12086 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12087 | TestCompletionCallback callback; |
| 12088 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12089 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12090 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12091 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12092 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12093 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12094 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12095 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12096 | HttpServerProperties* http_server_properties = |
| 12097 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12098 | EXPECT_TRUE( |
| 12099 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12100 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12101 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12102 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12103 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12104 | ASSERT_TRUE(response); |
| 12105 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12106 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12107 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12108 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12109 | |
| 12110 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12111 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12112 | EXPECT_EQ("hello world", response_data); |
| 12113 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12114 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 12115 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 12116 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 12117 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 12118 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12119 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12120 | } |
| 12121 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12122 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12123 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12124 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12125 | MockRead data_reads[] = { |
| 12126 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12127 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12128 | MockRead("\r\n"), |
| 12129 | MockRead("hello world"), |
| 12130 | MockRead(SYNCHRONOUS, OK), |
| 12131 | }; |
| 12132 | |
| 12133 | HttpRequestInfo request; |
| 12134 | request.method = "GET"; |
| 12135 | request.url = GURL("http://www.example.org/"); |
| 12136 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12137 | request.traffic_annotation = |
| 12138 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12139 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12140 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12141 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12142 | |
| 12143 | TestCompletionCallback callback; |
| 12144 | |
| 12145 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12146 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12147 | |
| 12148 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12149 | HttpServerProperties* http_server_properties = |
| 12150 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12151 | EXPECT_TRUE( |
| 12152 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12153 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12154 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12155 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12156 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12157 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12158 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12159 | ASSERT_TRUE(response); |
| 12160 | ASSERT_TRUE(response->headers); |
| 12161 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12162 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12163 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12164 | |
| 12165 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12166 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12167 | EXPECT_EQ("hello world", response_data); |
| 12168 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12169 | EXPECT_TRUE( |
| 12170 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12171 | } |
| 12172 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 12173 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12174 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12175 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12176 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 12177 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12178 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12179 | HttpRequestInfo request; |
| 12180 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12181 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12182 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12183 | request.traffic_annotation = |
| 12184 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12185 | |
| 12186 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12187 | StaticSocketDataProvider first_data; |
| 12188 | first_data.set_connect_data(mock_connect); |
| 12189 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12190 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12191 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12192 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12193 | |
| 12194 | MockRead data_reads[] = { |
| 12195 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12196 | MockRead(ASYNC, OK), |
| 12197 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12198 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12199 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12200 | |
| 12201 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12202 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12203 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12204 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12205 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 12206 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12207 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12208 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12209 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 12210 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12211 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12212 | TestCompletionCallback callback; |
| 12213 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12214 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12215 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12216 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12217 | } |
| 12218 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12219 | // Regression test for https://crbug.com/615497: |
| 12220 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12221 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12222 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12223 | HttpRequestInfo request; |
| 12224 | request.method = "GET"; |
| 12225 | request.url = GURL("http://www.example.org/"); |
| 12226 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12227 | request.traffic_annotation = |
| 12228 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12229 | |
| 12230 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12231 | StaticSocketDataProvider first_data; |
| 12232 | first_data.set_connect_data(mock_connect); |
| 12233 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 12234 | |
| 12235 | MockRead data_reads[] = { |
| 12236 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12237 | MockRead(ASYNC, OK), |
| 12238 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12239 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12240 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12241 | |
| 12242 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12243 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12244 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12245 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12246 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12247 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12248 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12249 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 12250 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12251 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12252 | TestCompletionCallback callback; |
| 12253 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12254 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12255 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12256 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12257 | } |
| 12258 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12259 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12260 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12261 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12262 | HttpServerProperties* http_server_properties = |
| 12263 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12264 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12265 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12266 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12267 | http_server_properties->SetQuicAlternativeService( |
| 12268 | test_server, alternative_service, expiration, |
| 12269 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12270 | EXPECT_EQ( |
| 12271 | 1u, |
| 12272 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12273 | |
| 12274 | // Send a clear header. |
| 12275 | MockRead data_reads[] = { |
| 12276 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12277 | MockRead("Alt-Svc: clear\r\n"), |
| 12278 | MockRead("\r\n"), |
| 12279 | MockRead("hello world"), |
| 12280 | MockRead(SYNCHRONOUS, OK), |
| 12281 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12282 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12283 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12284 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12285 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12286 | ssl.ssl_info.cert = |
| 12287 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12288 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12289 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12290 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12291 | HttpRequestInfo request; |
| 12292 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12293 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12294 | request.traffic_annotation = |
| 12295 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12296 | |
| 12297 | TestCompletionCallback callback; |
| 12298 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12299 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12300 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12301 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12302 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12303 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12304 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12305 | ASSERT_TRUE(response); |
| 12306 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12307 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12308 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12309 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12310 | |
| 12311 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12312 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12313 | EXPECT_EQ("hello world", response_data); |
| 12314 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12315 | EXPECT_TRUE( |
| 12316 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12317 | } |
| 12318 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12319 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12320 | MockRead data_reads[] = { |
| 12321 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12322 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 12323 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12324 | MockRead("hello world"), |
| 12325 | MockRead(SYNCHRONOUS, OK), |
| 12326 | }; |
| 12327 | |
| 12328 | HttpRequestInfo request; |
| 12329 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12330 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12331 | request.traffic_annotation = |
| 12332 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12333 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12334 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12335 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12336 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12337 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12338 | ssl.ssl_info.cert = |
| 12339 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12340 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12341 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12342 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12343 | TestCompletionCallback callback; |
| 12344 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12345 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12346 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12347 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12348 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12349 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12350 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12351 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12352 | HttpServerProperties* http_server_properties = |
| 12353 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12354 | EXPECT_TRUE( |
| 12355 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12356 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12357 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12358 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12359 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12360 | ASSERT_TRUE(response); |
| 12361 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12362 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12363 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12364 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12365 | |
| 12366 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12367 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12368 | EXPECT_EQ("hello world", response_data); |
| 12369 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12370 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 12371 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 12372 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 12373 | |
| 12374 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 12375 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12376 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12377 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 12378 | 1234); |
| 12379 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12380 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12381 | } |
| 12382 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12383 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12384 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12385 | HostPortPair alternative("alternative.example.org", 443); |
| 12386 | std::string origin_url = "https://origin.example.org:443"; |
| 12387 | std::string alternative_url = "https://alternative.example.org:443"; |
| 12388 | |
| 12389 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12390 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12391 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12392 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12393 | |
| 12394 | // HTTP/1.1 data for request. |
| 12395 | MockWrite http_writes[] = { |
| 12396 | MockWrite("GET / HTTP/1.1\r\n" |
| 12397 | "Host: alternative.example.org\r\n" |
| 12398 | "Connection: keep-alive\r\n\r\n"), |
| 12399 | }; |
| 12400 | |
| 12401 | MockRead http_reads[] = { |
| 12402 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12403 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12404 | "Content-Length: 40\r\n\r\n" |
| 12405 | "first HTTP/1.1 response from alternative"), |
| 12406 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12407 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12408 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12409 | |
| 12410 | StaticSocketDataProvider data_refused; |
| 12411 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12412 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12413 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12414 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12415 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12416 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12417 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12418 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12419 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12420 | http_server_properties->SetQuicAlternativeService( |
| 12421 | server, alternative_service, expiration, |
| 12422 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12423 | // Mark the QUIC alternative service as broken. |
| 12424 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 12425 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12426 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12427 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12428 | request.method = "GET"; |
| 12429 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12430 | request.traffic_annotation = |
| 12431 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12432 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12433 | TestCompletionCallback callback; |
| 12434 | NetErrorDetails details; |
| 12435 | EXPECT_FALSE(details.quic_broken); |
| 12436 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12437 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12438 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12439 | EXPECT_TRUE(details.quic_broken); |
| 12440 | } |
| 12441 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12442 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12443 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12444 | HostPortPair alternative1("alternative1.example.org", 443); |
| 12445 | HostPortPair alternative2("alternative2.example.org", 443); |
| 12446 | std::string origin_url = "https://origin.example.org:443"; |
| 12447 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 12448 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 12449 | |
| 12450 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 12451 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12452 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12453 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12454 | |
| 12455 | // HTTP/1.1 data for request. |
| 12456 | MockWrite http_writes[] = { |
| 12457 | MockWrite("GET / HTTP/1.1\r\n" |
| 12458 | "Host: alternative1.example.org\r\n" |
| 12459 | "Connection: keep-alive\r\n\r\n"), |
| 12460 | }; |
| 12461 | |
| 12462 | MockRead http_reads[] = { |
| 12463 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12464 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12465 | "Content-Length: 40\r\n\r\n" |
| 12466 | "first HTTP/1.1 response from alternative1"), |
| 12467 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12468 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12469 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12470 | |
| 12471 | StaticSocketDataProvider data_refused; |
| 12472 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12473 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12474 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12475 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12476 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12477 | session->http_server_properties(); |
| 12478 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12479 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12480 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 12481 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 12482 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12483 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12484 | alternative_service_info_vector.push_back( |
| 12485 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12486 | alternative_service1, expiration, |
| 12487 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12488 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12489 | alternative_service_info_vector.push_back( |
| 12490 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12491 | alternative_service2, expiration, |
| 12492 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12493 | |
| 12494 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12495 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12496 | |
| 12497 | // Mark one of the QUIC alternative service as broken. |
| 12498 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12499 | EXPECT_EQ(2u, |
| 12500 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12501 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12502 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12503 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12504 | request.method = "GET"; |
| 12505 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12506 | request.traffic_annotation = |
| 12507 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12508 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12509 | TestCompletionCallback callback; |
| 12510 | NetErrorDetails details; |
| 12511 | EXPECT_FALSE(details.quic_broken); |
| 12512 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12513 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12514 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12515 | EXPECT_FALSE(details.quic_broken); |
| 12516 | } |
| 12517 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12518 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12519 | HttpRequestInfo request; |
| 12520 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12521 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12522 | request.traffic_annotation = |
| 12523 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12524 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12525 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12526 | StaticSocketDataProvider first_data; |
| 12527 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12528 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12529 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12530 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12531 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12532 | |
| 12533 | MockRead data_reads[] = { |
| 12534 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12535 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12536 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12537 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12538 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12539 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12540 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12541 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12542 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12543 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12544 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12545 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12546 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 12547 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12548 | // Port is ignored by MockConnect anyway. |
| 12549 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12550 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12551 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12552 | http_server_properties->SetHttp2AlternativeService( |
| 12553 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12554 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12555 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12556 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12557 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12558 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12559 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12560 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12561 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12562 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12563 | ASSERT_TRUE(response); |
| 12564 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12565 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12566 | |
| 12567 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12568 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12569 | EXPECT_EQ("hello world", response_data); |
| 12570 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12571 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 12572 | http_server_properties->GetAlternativeServiceInfos(server); |
| 12573 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 12574 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12575 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12576 | EXPECT_TRUE( |
| 12577 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12578 | } |
| 12579 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12580 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12581 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12582 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12583 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12584 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12585 | HttpRequestInfo restricted_port_request; |
| 12586 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12587 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12588 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12589 | restricted_port_request.traffic_annotation = |
| 12590 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12591 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12592 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12593 | StaticSocketDataProvider first_data; |
| 12594 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12595 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12596 | |
| 12597 | MockRead data_reads[] = { |
| 12598 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12599 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12600 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12601 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12602 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12603 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12604 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12605 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12606 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12607 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12608 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12609 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12610 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12611 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12612 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12613 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12614 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12615 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12616 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12617 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12618 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12619 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12620 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12621 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12622 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12623 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12624 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12625 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12626 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12627 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12628 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12629 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12630 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 12631 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 12632 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12633 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12634 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12635 | |
| 12636 | HttpRequestInfo restricted_port_request; |
| 12637 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12638 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12639 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12640 | restricted_port_request.traffic_annotation = |
| 12641 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12642 | |
| 12643 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12644 | StaticSocketDataProvider first_data; |
| 12645 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12646 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12647 | |
| 12648 | MockRead data_reads[] = { |
| 12649 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12650 | MockRead("hello world"), |
| 12651 | MockRead(ASYNC, OK), |
| 12652 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12653 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12654 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12655 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12656 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12657 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12658 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12659 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12660 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12661 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12662 | session->http_server_properties(); |
| 12663 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12664 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12665 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12666 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12667 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12668 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12669 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12670 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12671 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12672 | TestCompletionCallback callback; |
| 12673 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12674 | EXPECT_EQ(ERR_IO_PENDING, |
| 12675 | trans.Start(&restricted_port_request, callback.callback(), |
| 12676 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12677 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12678 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12679 | } |
| 12680 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12681 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12682 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12683 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12684 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12685 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12686 | HttpRequestInfo restricted_port_request; |
| 12687 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12688 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12689 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12690 | restricted_port_request.traffic_annotation = |
| 12691 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12692 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12693 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12694 | StaticSocketDataProvider first_data; |
| 12695 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12696 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12697 | |
| 12698 | MockRead data_reads[] = { |
| 12699 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12700 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12701 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12702 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12703 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12704 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12705 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12706 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12707 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12708 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12709 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12710 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12711 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12712 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12713 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12714 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12715 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12716 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12717 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12718 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12719 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12720 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12721 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12722 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12723 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12724 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12725 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12726 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12727 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12728 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12729 | } |
| 12730 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12731 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12732 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12733 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12734 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12735 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12736 | HttpRequestInfo unrestricted_port_request; |
| 12737 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12738 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12739 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12740 | unrestricted_port_request.traffic_annotation = |
| 12741 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12742 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12743 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12744 | StaticSocketDataProvider first_data; |
| 12745 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12746 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12747 | |
| 12748 | MockRead data_reads[] = { |
| 12749 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12750 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12751 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12752 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12753 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12754 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12755 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12756 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12757 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12758 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12759 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12760 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12761 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12762 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12763 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12764 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12765 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12766 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12767 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12768 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12769 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12770 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12771 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12772 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12773 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12774 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12775 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12776 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12777 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12778 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12779 | } |
| 12780 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12781 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12782 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12783 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12784 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12785 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12786 | HttpRequestInfo unrestricted_port_request; |
| 12787 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12788 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12789 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12790 | unrestricted_port_request.traffic_annotation = |
| 12791 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12792 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12793 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12794 | StaticSocketDataProvider first_data; |
| 12795 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12796 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12797 | |
| 12798 | MockRead data_reads[] = { |
| 12799 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12800 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12801 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12802 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12803 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12804 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12805 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12806 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12807 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12808 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12809 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12810 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12811 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12812 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 12813 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12814 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12815 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12816 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12817 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12818 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12819 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12820 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12821 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12822 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12823 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12824 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12825 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12826 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12827 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12828 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12829 | } |
| 12830 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12831 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
Xida Chen | 9bfe0b6 | 2018-04-24 19:52:21 | [diff] [blame] | 12832 | // to an unsafe port, and that we resume the second HttpStreamFactory::Job once |
| 12833 | // the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12834 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12835 | HttpRequestInfo request; |
| 12836 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12837 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12838 | request.traffic_annotation = |
| 12839 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12840 | |
| 12841 | // The alternate protocol request will error out before we attempt to connect, |
| 12842 | // so only the standard HTTP request will try to connect. |
| 12843 | MockRead data_reads[] = { |
| 12844 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12845 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12846 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12847 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12848 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12849 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12850 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12851 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12852 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12853 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12854 | session->http_server_properties(); |
| 12855 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12856 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12857 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12858 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12859 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12860 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12861 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12862 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12863 | TestCompletionCallback callback; |
| 12864 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12865 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12866 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12867 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12868 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12869 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12870 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12871 | ASSERT_TRUE(response); |
| 12872 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12873 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12874 | |
| 12875 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12876 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12877 | EXPECT_EQ("hello world", response_data); |
| 12878 | } |
| 12879 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12880 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12881 | HttpRequestInfo request; |
| 12882 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12883 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12884 | request.traffic_annotation = |
| 12885 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12886 | |
| 12887 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12888 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12889 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12890 | MockRead("\r\n"), |
| 12891 | MockRead("hello world"), |
| 12892 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12893 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12894 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12895 | StaticSocketDataProvider first_transaction(data_reads, |
| 12896 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12897 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12898 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12899 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12900 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12901 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12902 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12903 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12904 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12905 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12906 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12907 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 12908 | spdy::SpdySerializedFrame resp( |
| 12909 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12910 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12911 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12912 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12913 | }; |
| 12914 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12915 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12916 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12917 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12918 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12919 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12920 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 12921 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12922 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12923 | &hanging_non_alternate_protocol_socket); |
| 12924 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12925 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12926 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12927 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12928 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12929 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12930 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12931 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12932 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12933 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12934 | |
| 12935 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12936 | ASSERT_TRUE(response); |
| 12937 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12938 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12939 | |
| 12940 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12941 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12942 | EXPECT_EQ("hello world", response_data); |
| 12943 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12944 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12945 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12946 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12947 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12948 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12949 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12950 | |
| 12951 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12952 | ASSERT_TRUE(response); |
| 12953 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12954 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12955 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12956 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12957 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12958 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12959 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12960 | } |
| 12961 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12962 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12963 | HttpRequestInfo request; |
| 12964 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12965 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12966 | request.traffic_annotation = |
| 12967 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12968 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12969 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12970 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12971 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12972 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12973 | MockRead("\r\n"), |
| 12974 | MockRead("hello world"), |
| 12975 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12976 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12977 | }; |
| 12978 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12979 | StaticSocketDataProvider http11_data(data_reads, base::span<MockWrite>()); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12980 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12981 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12982 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12983 | ssl_http11.ssl_info.cert = |
| 12984 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12985 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12986 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 12987 | |
| 12988 | // Second transaction starts an alternative and a non-alternative Job. |
| 12989 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12990 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12991 | StaticSocketDataProvider hanging_socket1; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12992 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12993 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 12994 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12995 | StaticSocketDataProvider hanging_socket2; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12996 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 12997 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12998 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12999 | // Third transaction starts an alternative and a non-alternative job. |
| 13000 | // The non-alternative job hangs, but the alternative one succeeds. |
| 13001 | // The second transaction, still pending, binds to this socket. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13002 | spdy::SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13003 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13004 | spdy::SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13005 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13006 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13007 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13008 | }; |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13009 | spdy::SpdySerializedFrame resp1( |
| 13010 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13011 | spdy::SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13012 | spdy::SpdySerializedFrame resp2( |
| 13013 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13014 | spdy::SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13015 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13016 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 13017 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13018 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13019 | }; |
| 13020 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13021 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13022 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13023 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13024 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13025 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13026 | StaticSocketDataProvider hanging_socket3; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13027 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 13028 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13029 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13030 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13031 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13032 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13033 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13034 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13035 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13036 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13037 | |
| 13038 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13039 | ASSERT_TRUE(response); |
| 13040 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13041 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13042 | |
| 13043 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13044 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13045 | EXPECT_EQ("hello world", response_data); |
| 13046 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13047 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13048 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13049 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13050 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13051 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13052 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13053 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13054 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13055 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13056 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13057 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 13058 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13059 | |
| 13060 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13061 | ASSERT_TRUE(response); |
| 13062 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13063 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13064 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13065 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13066 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13067 | EXPECT_EQ("hello!", response_data); |
| 13068 | |
| 13069 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13070 | ASSERT_TRUE(response); |
| 13071 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13072 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13073 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13074 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13075 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13076 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13077 | } |
| 13078 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13079 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
Bence Béky | bcae3709 | 2018-06-12 04:18:53 | [diff] [blame] | 13080 | session_deps_.host_resolver->set_synchronous_mode(true); |
| 13081 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13082 | HttpRequestInfo request; |
| 13083 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13084 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13085 | request.traffic_annotation = |
| 13086 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13087 | |
| 13088 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13089 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13090 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13091 | MockRead("\r\n"), |
| 13092 | MockRead("hello world"), |
| 13093 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13094 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13095 | }; |
| 13096 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13097 | StaticSocketDataProvider first_transaction(data_reads, |
| 13098 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13099 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13100 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13101 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 13102 | ssl.ssl_info.cert = |
| 13103 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 13104 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13105 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13106 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13107 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13108 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13109 | hanging_alternate_protocol_socket.set_connect_data( |
| 13110 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13111 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13112 | &hanging_alternate_protocol_socket); |
| 13113 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13114 | // 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] | 13115 | StaticSocketDataProvider second_transaction(data_reads, |
| 13116 | base::span<MockWrite>()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13117 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13118 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13119 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13120 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13121 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13122 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13123 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13124 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13125 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13126 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13127 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13128 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13129 | |
| 13130 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13131 | ASSERT_TRUE(response); |
| 13132 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13133 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13134 | |
| 13135 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13136 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13137 | EXPECT_EQ("hello world", response_data); |
| 13138 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13139 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13140 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13141 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13142 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13143 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13144 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13145 | |
| 13146 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13147 | ASSERT_TRUE(response); |
| 13148 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13149 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13150 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13151 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13152 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13153 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13154 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13155 | } |
| 13156 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13157 | // Test that proxy is resolved using the origin url, |
| 13158 | // regardless of the alternative server. |
| 13159 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 13160 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 13161 | ProxyConfig proxy_config; |
| 13162 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 13163 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13164 | auto proxy_config_service = std::make_unique<ProxyConfigServiceFixed>( |
| 13165 | ProxyConfigWithAnnotation(proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13166 | |
| 13167 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13168 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13169 | &capturing_proxy_resolver); |
| 13170 | |
| 13171 | TestNetLog net_log; |
| 13172 | |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 13173 | session_deps_.proxy_resolution_service = |
| 13174 | std::make_unique<ProxyResolutionService>( |
| 13175 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 13176 | &net_log); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13177 | |
| 13178 | session_deps_.net_log = &net_log; |
| 13179 | |
| 13180 | // Configure alternative service with a hostname that is not bypassed by the |
| 13181 | // proxy. |
| 13182 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13183 | HttpServerProperties* http_server_properties = |
| 13184 | session->http_server_properties(); |
| 13185 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13186 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13187 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13188 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13189 | http_server_properties->SetHttp2AlternativeService( |
| 13190 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13191 | |
| 13192 | // Non-alternative job should hang. |
| 13193 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13194 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13195 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 13196 | session_deps_.socket_factory->AddSocketDataProvider( |
| 13197 | &hanging_alternate_protocol_socket); |
| 13198 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13199 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13200 | |
| 13201 | HttpRequestInfo request; |
| 13202 | request.method = "GET"; |
| 13203 | request.url = GURL("https://www.example.org/"); |
| 13204 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13205 | request.traffic_annotation = |
| 13206 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13207 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13208 | spdy::SpdySerializedFrame req( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13209 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 13210 | |
| 13211 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 13212 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13213 | spdy::SpdySerializedFrame resp( |
| 13214 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13215 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13216 | MockRead spdy_reads[] = { |
| 13217 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 13218 | }; |
| 13219 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13220 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13221 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 13222 | |
| 13223 | TestCompletionCallback callback; |
| 13224 | |
| 13225 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13226 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13227 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13228 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 13229 | |
| 13230 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 13231 | ASSERT_TRUE(response); |
| 13232 | ASSERT_TRUE(response->headers); |
| 13233 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13234 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13235 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13236 | |
| 13237 | std::string response_data; |
| 13238 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 13239 | EXPECT_EQ("hello!", response_data); |
| 13240 | |
| 13241 | // Origin host bypasses proxy, no resolution should have happened. |
| 13242 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 13243 | } |
| 13244 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13245 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13246 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13247 | proxy_config.set_auto_detect(true); |
| 13248 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 13249 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13250 | CapturingProxyResolver capturing_proxy_resolver; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13251 | session_deps_.proxy_resolution_service = |
| 13252 | std::make_unique<ProxyResolutionService>( |
| 13253 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 13254 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 13255 | std::make_unique<CapturingProxyResolverFactory>( |
| 13256 | &capturing_proxy_resolver), |
| 13257 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13258 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13259 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13260 | |
| 13261 | HttpRequestInfo request; |
| 13262 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13263 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13264 | request.traffic_annotation = |
| 13265 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13266 | |
| 13267 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13268 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13269 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13270 | MockRead("\r\n"), |
| 13271 | MockRead("hello world"), |
| 13272 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13273 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13274 | }; |
| 13275 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13276 | StaticSocketDataProvider first_transaction(data_reads, |
| 13277 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13278 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13279 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13280 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13281 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13282 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13283 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13284 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13285 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13286 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13287 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13288 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13289 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13290 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13291 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13292 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13293 | }; |
| 13294 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13295 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 13296 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13297 | spdy::SpdySerializedFrame resp( |
| 13298 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13299 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13300 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13301 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 13302 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13303 | }; |
| 13304 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13305 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13306 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13307 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13308 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13309 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13310 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 13311 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13312 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13313 | &hanging_non_alternate_protocol_socket); |
| 13314 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13315 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13316 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13317 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13318 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13319 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13320 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13321 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13322 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13323 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 13324 | |
| 13325 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13326 | ASSERT_TRUE(response); |
| 13327 | ASSERT_TRUE(response->headers); |
| 13328 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 13329 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13330 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13331 | |
| 13332 | std::string response_data; |
| 13333 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 13334 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13335 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13336 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13337 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13338 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13339 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13340 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13341 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13342 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13343 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13344 | ASSERT_TRUE(response); |
| 13345 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13346 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13347 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13348 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13349 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13350 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13351 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13352 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 13353 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13354 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13355 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13356 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13357 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13358 | LoadTimingInfo load_timing_info; |
| 13359 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 13360 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13361 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13362 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13363 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13364 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 13365 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13366 | HttpRequestInfo request; |
| 13367 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13368 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13369 | request.traffic_annotation = |
| 13370 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13371 | |
| 13372 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13373 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13374 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13375 | MockRead("\r\n"), |
| 13376 | MockRead("hello world"), |
| 13377 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13378 | }; |
| 13379 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13380 | StaticSocketDataProvider first_transaction(data_reads, |
| 13381 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13382 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13383 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13384 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13385 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13386 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13387 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13388 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13389 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13390 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13391 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13392 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13393 | spdy::SpdySerializedFrame resp( |
| 13394 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13395 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13396 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13397 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13398 | }; |
| 13399 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13400 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13401 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13402 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 13403 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13404 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13405 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13406 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13407 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13408 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13409 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13410 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13411 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13412 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13413 | |
| 13414 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13415 | ASSERT_TRUE(response); |
| 13416 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13417 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13418 | |
| 13419 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13420 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13421 | EXPECT_EQ("hello world", response_data); |
| 13422 | |
| 13423 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13424 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13425 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 13426 | PRIVACY_MODE_DISABLED, |
| 13427 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13428 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 13429 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 13430 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13431 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13432 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13433 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13434 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13435 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13436 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13437 | |
| 13438 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13439 | ASSERT_TRUE(response); |
| 13440 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13441 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13442 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13443 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13444 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13445 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13446 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13447 | } |
| 13448 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13449 | // GenerateAuthToken is a mighty big test. |
| 13450 | // It tests all permutation of GenerateAuthToken behavior: |
| 13451 | // - Synchronous and Asynchronous completion. |
| 13452 | // - OK or error on completion. |
| 13453 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 13454 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 13455 | // - Non-authenticating and authenticating backend. |
| 13456 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 13457 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13458 | // problems generating an auth token for an authenticating proxy, we don't |
| 13459 | // need to test all permutations of the backend server). |
| 13460 | // |
| 13461 | // The test proceeds by going over each of the configuration cases, and |
| 13462 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 13463 | // specifies both the configuration for the test as well as the expectations |
| 13464 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13465 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13466 | static const char kServer[] = "http://www.example.com"; |
| 13467 | static const char kSecureServer[] = "https://www.example.com"; |
| 13468 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13469 | |
| 13470 | enum AuthTiming { |
| 13471 | AUTH_NONE, |
| 13472 | AUTH_SYNC, |
| 13473 | AUTH_ASYNC, |
| 13474 | }; |
| 13475 | |
| 13476 | const MockWrite kGet( |
| 13477 | "GET / HTTP/1.1\r\n" |
| 13478 | "Host: www.example.com\r\n" |
| 13479 | "Connection: keep-alive\r\n\r\n"); |
| 13480 | const MockWrite kGetProxy( |
| 13481 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13482 | "Host: www.example.com\r\n" |
| 13483 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13484 | const MockWrite kGetAuth( |
| 13485 | "GET / HTTP/1.1\r\n" |
| 13486 | "Host: www.example.com\r\n" |
| 13487 | "Connection: keep-alive\r\n" |
| 13488 | "Authorization: auth_token\r\n\r\n"); |
| 13489 | const MockWrite kGetProxyAuth( |
| 13490 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13491 | "Host: www.example.com\r\n" |
| 13492 | "Proxy-Connection: keep-alive\r\n" |
| 13493 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13494 | const MockWrite kGetAuthThroughProxy( |
| 13495 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13496 | "Host: www.example.com\r\n" |
| 13497 | "Proxy-Connection: keep-alive\r\n" |
| 13498 | "Authorization: auth_token\r\n\r\n"); |
| 13499 | const MockWrite kGetAuthWithProxyAuth( |
| 13500 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13501 | "Host: www.example.com\r\n" |
| 13502 | "Proxy-Connection: keep-alive\r\n" |
| 13503 | "Proxy-Authorization: auth_token\r\n" |
| 13504 | "Authorization: auth_token\r\n\r\n"); |
| 13505 | const MockWrite kConnect( |
| 13506 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13507 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13508 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13509 | const MockWrite kConnectProxyAuth( |
| 13510 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13511 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13512 | "Proxy-Connection: keep-alive\r\n" |
| 13513 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13514 | |
| 13515 | const MockRead kSuccess( |
| 13516 | "HTTP/1.1 200 OK\r\n" |
| 13517 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13518 | "Content-Length: 3\r\n\r\n" |
| 13519 | "Yes"); |
| 13520 | const MockRead kFailure( |
| 13521 | "Should not be called."); |
| 13522 | const MockRead kServerChallenge( |
| 13523 | "HTTP/1.1 401 Unauthorized\r\n" |
| 13524 | "WWW-Authenticate: Mock realm=server\r\n" |
| 13525 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13526 | "Content-Length: 14\r\n\r\n" |
| 13527 | "Unauthorized\r\n"); |
| 13528 | const MockRead kProxyChallenge( |
| 13529 | "HTTP/1.1 407 Unauthorized\r\n" |
| 13530 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 13531 | "Proxy-Connection: close\r\n" |
| 13532 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13533 | "Content-Length: 14\r\n\r\n" |
| 13534 | "Unauthorized\r\n"); |
| 13535 | const MockRead kProxyConnected( |
| 13536 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 13537 | |
| 13538 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 13539 | // no constructors, but the C++ compiler on Windows warns about |
| 13540 | // unspecified data in compound literals. So, moved to using constructors, |
| 13541 | // and TestRound's created with the default constructor should not be used. |
| 13542 | struct TestRound { |
| 13543 | TestRound() |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13544 | : expected_rv(ERR_UNEXPECTED), |
| 13545 | extra_write(nullptr), |
| 13546 | extra_read(nullptr) {} |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 13547 | TestRound(const MockWrite& write_arg, |
| 13548 | const MockRead& read_arg, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13549 | int expected_rv_arg) |
| 13550 | : write(write_arg), |
| 13551 | read(read_arg), |
| 13552 | expected_rv(expected_rv_arg), |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13553 | extra_write(nullptr), |
| 13554 | extra_read(nullptr) {} |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13555 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 13556 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 13557 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13558 | : write(write_arg), |
| 13559 | read(read_arg), |
| 13560 | expected_rv(expected_rv_arg), |
| 13561 | extra_write(extra_write_arg), |
| 13562 | extra_read(extra_read_arg) { |
| 13563 | } |
| 13564 | MockWrite write; |
| 13565 | MockRead read; |
| 13566 | int expected_rv; |
| 13567 | const MockWrite* extra_write; |
| 13568 | const MockRead* extra_read; |
| 13569 | }; |
| 13570 | |
| 13571 | static const int kNoSSL = 500; |
| 13572 | |
| 13573 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13574 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13575 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13576 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13577 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13578 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13579 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13580 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13581 | int num_auth_rounds; |
| 13582 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13583 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13584 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13585 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13586 | {__LINE__, |
| 13587 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13588 | AUTH_NONE, |
| 13589 | OK, |
| 13590 | kServer, |
| 13591 | AUTH_NONE, |
| 13592 | OK, |
| 13593 | 1, |
| 13594 | kNoSSL, |
| 13595 | {TestRound(kGet, kSuccess, OK)}}, |
| 13596 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13597 | {__LINE__, |
| 13598 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13599 | AUTH_NONE, |
| 13600 | OK, |
| 13601 | kServer, |
| 13602 | AUTH_SYNC, |
| 13603 | OK, |
| 13604 | 2, |
| 13605 | kNoSSL, |
| 13606 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13607 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13608 | {__LINE__, |
| 13609 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13610 | AUTH_NONE, |
| 13611 | OK, |
| 13612 | kServer, |
| 13613 | AUTH_SYNC, |
| 13614 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13615 | 3, |
| 13616 | kNoSSL, |
| 13617 | {TestRound(kGet, kServerChallenge, OK), |
| 13618 | TestRound(kGet, kServerChallenge, OK), |
| 13619 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13620 | {__LINE__, |
| 13621 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13622 | AUTH_NONE, |
| 13623 | OK, |
| 13624 | kServer, |
| 13625 | AUTH_SYNC, |
| 13626 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 13627 | 2, |
| 13628 | kNoSSL, |
| 13629 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13630 | {__LINE__, |
| 13631 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13632 | AUTH_NONE, |
| 13633 | OK, |
| 13634 | kServer, |
| 13635 | AUTH_SYNC, |
| 13636 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 13637 | 2, |
| 13638 | kNoSSL, |
| 13639 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13640 | {__LINE__, |
| 13641 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13642 | AUTH_SYNC, |
| 13643 | ERR_FAILED, |
| 13644 | kServer, |
| 13645 | AUTH_NONE, |
| 13646 | OK, |
| 13647 | 2, |
| 13648 | kNoSSL, |
| 13649 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13650 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13651 | {__LINE__, |
| 13652 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13653 | AUTH_ASYNC, |
| 13654 | ERR_FAILED, |
| 13655 | kServer, |
| 13656 | AUTH_NONE, |
| 13657 | OK, |
| 13658 | 2, |
| 13659 | kNoSSL, |
| 13660 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13661 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13662 | {__LINE__, |
| 13663 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13664 | AUTH_NONE, |
| 13665 | OK, |
| 13666 | kServer, |
| 13667 | AUTH_SYNC, |
| 13668 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13669 | 2, |
| 13670 | kNoSSL, |
| 13671 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13672 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13673 | {__LINE__, |
| 13674 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13675 | AUTH_NONE, |
| 13676 | OK, |
| 13677 | kServer, |
| 13678 | AUTH_ASYNC, |
| 13679 | ERR_FAILED, |
| 13680 | 2, |
| 13681 | kNoSSL, |
| 13682 | {TestRound(kGet, kServerChallenge, OK), |
| 13683 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13684 | {__LINE__, |
| 13685 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13686 | AUTH_NONE, |
| 13687 | OK, |
| 13688 | kServer, |
| 13689 | AUTH_ASYNC, |
| 13690 | OK, |
| 13691 | 2, |
| 13692 | kNoSSL, |
| 13693 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13694 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13695 | {__LINE__, |
| 13696 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13697 | AUTH_NONE, |
| 13698 | OK, |
| 13699 | kServer, |
| 13700 | AUTH_ASYNC, |
| 13701 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13702 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13703 | kNoSSL, |
| 13704 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13705 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 13706 | TestRound(kGet, kServerChallenge, OK), |
| 13707 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13708 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13709 | {__LINE__, |
| 13710 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13711 | AUTH_NONE, |
| 13712 | OK, |
| 13713 | kServer, |
| 13714 | AUTH_NONE, |
| 13715 | OK, |
| 13716 | 1, |
| 13717 | kNoSSL, |
| 13718 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 13719 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13720 | {__LINE__, |
| 13721 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13722 | AUTH_NONE, |
| 13723 | OK, |
| 13724 | kServer, |
| 13725 | AUTH_SYNC, |
| 13726 | OK, |
| 13727 | 2, |
| 13728 | kNoSSL, |
| 13729 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13730 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13731 | {__LINE__, |
| 13732 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13733 | AUTH_NONE, |
| 13734 | OK, |
| 13735 | kServer, |
| 13736 | AUTH_SYNC, |
| 13737 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13738 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13739 | kNoSSL, |
| 13740 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13741 | TestRound(kGetProxy, kServerChallenge, OK), |
| 13742 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13743 | {__LINE__, |
| 13744 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13745 | AUTH_NONE, |
| 13746 | OK, |
| 13747 | kServer, |
| 13748 | AUTH_ASYNC, |
| 13749 | OK, |
| 13750 | 2, |
| 13751 | kNoSSL, |
| 13752 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13753 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13754 | {__LINE__, |
| 13755 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13756 | AUTH_NONE, |
| 13757 | OK, |
| 13758 | kServer, |
| 13759 | AUTH_ASYNC, |
| 13760 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13761 | 2, |
| 13762 | kNoSSL, |
| 13763 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13764 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13765 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13766 | {__LINE__, |
| 13767 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13768 | AUTH_SYNC, |
| 13769 | OK, |
| 13770 | kServer, |
| 13771 | AUTH_NONE, |
| 13772 | OK, |
| 13773 | 2, |
| 13774 | kNoSSL, |
| 13775 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [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_SYNC, |
| 13780 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13781 | kServer, |
| 13782 | AUTH_NONE, |
| 13783 | OK, |
| 13784 | 2, |
| 13785 | kNoSSL, |
| 13786 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13787 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13788 | {__LINE__, |
| 13789 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13790 | AUTH_ASYNC, |
| 13791 | OK, |
| 13792 | kServer, |
| 13793 | AUTH_NONE, |
| 13794 | OK, |
| 13795 | 2, |
| 13796 | kNoSSL, |
| 13797 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13798 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13799 | {__LINE__, |
| 13800 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13801 | AUTH_ASYNC, |
| 13802 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13803 | kServer, |
| 13804 | AUTH_NONE, |
| 13805 | OK, |
| 13806 | 2, |
| 13807 | kNoSSL, |
| 13808 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13809 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13810 | {__LINE__, |
| 13811 | kProxy, |
| 13812 | AUTH_ASYNC, |
| 13813 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13814 | kServer, |
| 13815 | AUTH_NONE, |
| 13816 | OK, |
| 13817 | 3, |
| 13818 | kNoSSL, |
| 13819 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13820 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13821 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13822 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13823 | {__LINE__, |
| 13824 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13825 | AUTH_SYNC, |
| 13826 | OK, |
| 13827 | kServer, |
| 13828 | AUTH_SYNC, |
| 13829 | OK, |
| 13830 | 3, |
| 13831 | kNoSSL, |
| 13832 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13833 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13834 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13835 | {__LINE__, |
| 13836 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13837 | AUTH_SYNC, |
| 13838 | OK, |
| 13839 | kServer, |
| 13840 | AUTH_SYNC, |
| 13841 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13842 | 3, |
| 13843 | kNoSSL, |
| 13844 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13845 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13846 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13847 | {__LINE__, |
| 13848 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13849 | AUTH_ASYNC, |
| 13850 | OK, |
| 13851 | kServer, |
| 13852 | AUTH_SYNC, |
| 13853 | OK, |
| 13854 | 3, |
| 13855 | kNoSSL, |
| 13856 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13857 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13858 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13859 | {__LINE__, |
| 13860 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13861 | AUTH_ASYNC, |
| 13862 | OK, |
| 13863 | kServer, |
| 13864 | AUTH_SYNC, |
| 13865 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13866 | 3, |
| 13867 | kNoSSL, |
| 13868 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13869 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13870 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13871 | {__LINE__, |
| 13872 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13873 | AUTH_SYNC, |
| 13874 | OK, |
| 13875 | kServer, |
| 13876 | AUTH_ASYNC, |
| 13877 | OK, |
| 13878 | 3, |
| 13879 | kNoSSL, |
| 13880 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13881 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13882 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13883 | {__LINE__, |
| 13884 | kProxy, |
| 13885 | AUTH_SYNC, |
| 13886 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13887 | kServer, |
| 13888 | AUTH_ASYNC, |
| 13889 | OK, |
| 13890 | 4, |
| 13891 | kNoSSL, |
| 13892 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13893 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13894 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13895 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 13896 | {__LINE__, |
| 13897 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13898 | AUTH_SYNC, |
| 13899 | OK, |
| 13900 | kServer, |
| 13901 | AUTH_ASYNC, |
| 13902 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13903 | 3, |
| 13904 | kNoSSL, |
| 13905 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13906 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13907 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13908 | {__LINE__, |
| 13909 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13910 | AUTH_ASYNC, |
| 13911 | OK, |
| 13912 | kServer, |
| 13913 | AUTH_ASYNC, |
| 13914 | OK, |
| 13915 | 3, |
| 13916 | kNoSSL, |
| 13917 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13918 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13919 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13920 | {__LINE__, |
| 13921 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13922 | AUTH_ASYNC, |
| 13923 | OK, |
| 13924 | kServer, |
| 13925 | AUTH_ASYNC, |
| 13926 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13927 | 3, |
| 13928 | kNoSSL, |
| 13929 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13930 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13931 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13932 | {__LINE__, |
| 13933 | kProxy, |
| 13934 | AUTH_ASYNC, |
| 13935 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13936 | kServer, |
| 13937 | AUTH_ASYNC, |
| 13938 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13939 | 4, |
| 13940 | kNoSSL, |
| 13941 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13942 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13943 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13944 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13945 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13946 | {__LINE__, |
| 13947 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13948 | AUTH_NONE, |
| 13949 | OK, |
| 13950 | kSecureServer, |
| 13951 | AUTH_NONE, |
| 13952 | OK, |
| 13953 | 1, |
| 13954 | 0, |
| 13955 | {TestRound(kGet, kSuccess, OK)}}, |
| 13956 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13957 | {__LINE__, |
| 13958 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13959 | AUTH_NONE, |
| 13960 | OK, |
| 13961 | kSecureServer, |
| 13962 | AUTH_SYNC, |
| 13963 | OK, |
| 13964 | 2, |
| 13965 | 0, |
| 13966 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13967 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13968 | {__LINE__, |
| 13969 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13970 | AUTH_NONE, |
| 13971 | OK, |
| 13972 | kSecureServer, |
| 13973 | AUTH_SYNC, |
| 13974 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13975 | 2, |
| 13976 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13977 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13978 | {__LINE__, |
| 13979 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13980 | AUTH_NONE, |
| 13981 | OK, |
| 13982 | kSecureServer, |
| 13983 | AUTH_ASYNC, |
| 13984 | OK, |
| 13985 | 2, |
| 13986 | 0, |
| 13987 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13988 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13989 | {__LINE__, |
| 13990 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13991 | AUTH_NONE, |
| 13992 | OK, |
| 13993 | kSecureServer, |
| 13994 | AUTH_ASYNC, |
| 13995 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13996 | 2, |
| 13997 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13998 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13999 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14000 | {__LINE__, |
| 14001 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14002 | AUTH_NONE, |
| 14003 | OK, |
| 14004 | kSecureServer, |
| 14005 | AUTH_NONE, |
| 14006 | OK, |
| 14007 | 1, |
| 14008 | 0, |
| 14009 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 14010 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14011 | {__LINE__, |
| 14012 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14013 | AUTH_NONE, |
| 14014 | OK, |
| 14015 | kSecureServer, |
| 14016 | AUTH_SYNC, |
| 14017 | OK, |
| 14018 | 2, |
| 14019 | 0, |
| 14020 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14021 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14022 | {__LINE__, |
| 14023 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14024 | AUTH_NONE, |
| 14025 | OK, |
| 14026 | kSecureServer, |
| 14027 | AUTH_SYNC, |
| 14028 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14029 | 2, |
| 14030 | 0, |
| 14031 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14032 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14033 | {__LINE__, |
| 14034 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14035 | AUTH_NONE, |
| 14036 | OK, |
| 14037 | kSecureServer, |
| 14038 | AUTH_ASYNC, |
| 14039 | OK, |
| 14040 | 2, |
| 14041 | 0, |
| 14042 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14043 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14044 | {__LINE__, |
| 14045 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14046 | AUTH_NONE, |
| 14047 | OK, |
| 14048 | kSecureServer, |
| 14049 | AUTH_ASYNC, |
| 14050 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14051 | 2, |
| 14052 | 0, |
| 14053 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14054 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14055 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14056 | {__LINE__, |
| 14057 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14058 | AUTH_SYNC, |
| 14059 | OK, |
| 14060 | kSecureServer, |
| 14061 | AUTH_NONE, |
| 14062 | OK, |
| 14063 | 2, |
| 14064 | 1, |
| 14065 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14066 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14067 | {__LINE__, |
| 14068 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14069 | AUTH_SYNC, |
| 14070 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14071 | kSecureServer, |
| 14072 | AUTH_NONE, |
| 14073 | OK, |
| 14074 | 2, |
| 14075 | kNoSSL, |
| 14076 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14077 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14078 | {__LINE__, |
| 14079 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14080 | AUTH_SYNC, |
| 14081 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 14082 | kSecureServer, |
| 14083 | AUTH_NONE, |
| 14084 | OK, |
| 14085 | 2, |
| 14086 | kNoSSL, |
| 14087 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14088 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14089 | {__LINE__, |
| 14090 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14091 | AUTH_SYNC, |
| 14092 | ERR_UNEXPECTED, |
| 14093 | kSecureServer, |
| 14094 | AUTH_NONE, |
| 14095 | OK, |
| 14096 | 2, |
| 14097 | kNoSSL, |
| 14098 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14099 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14100 | {__LINE__, |
| 14101 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14102 | AUTH_ASYNC, |
| 14103 | OK, |
| 14104 | kSecureServer, |
| 14105 | AUTH_NONE, |
| 14106 | OK, |
| 14107 | 2, |
| 14108 | 1, |
| 14109 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14110 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14111 | {__LINE__, |
| 14112 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14113 | AUTH_ASYNC, |
| 14114 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14115 | kSecureServer, |
| 14116 | AUTH_NONE, |
| 14117 | OK, |
| 14118 | 2, |
| 14119 | kNoSSL, |
| 14120 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14121 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14122 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14123 | {__LINE__, |
| 14124 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14125 | AUTH_SYNC, |
| 14126 | OK, |
| 14127 | kSecureServer, |
| 14128 | AUTH_SYNC, |
| 14129 | OK, |
| 14130 | 3, |
| 14131 | 1, |
| 14132 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14133 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14134 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14135 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14136 | {__LINE__, |
| 14137 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14138 | AUTH_SYNC, |
| 14139 | OK, |
| 14140 | kSecureServer, |
| 14141 | AUTH_SYNC, |
| 14142 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14143 | 3, |
| 14144 | 1, |
| 14145 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14146 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14147 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14148 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14149 | {__LINE__, |
| 14150 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14151 | AUTH_ASYNC, |
| 14152 | OK, |
| 14153 | kSecureServer, |
| 14154 | AUTH_SYNC, |
| 14155 | OK, |
| 14156 | 3, |
| 14157 | 1, |
| 14158 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14159 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14160 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14161 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14162 | {__LINE__, |
| 14163 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14164 | AUTH_ASYNC, |
| 14165 | OK, |
| 14166 | kSecureServer, |
| 14167 | AUTH_SYNC, |
| 14168 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14169 | 3, |
| 14170 | 1, |
| 14171 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14172 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14173 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14174 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14175 | {__LINE__, |
| 14176 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14177 | AUTH_SYNC, |
| 14178 | OK, |
| 14179 | kSecureServer, |
| 14180 | AUTH_ASYNC, |
| 14181 | OK, |
| 14182 | 3, |
| 14183 | 1, |
| 14184 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14185 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14186 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14187 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14188 | {__LINE__, |
| 14189 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14190 | AUTH_SYNC, |
| 14191 | OK, |
| 14192 | kSecureServer, |
| 14193 | AUTH_ASYNC, |
| 14194 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14195 | 3, |
| 14196 | 1, |
| 14197 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14198 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14199 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14200 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14201 | {__LINE__, |
| 14202 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14203 | AUTH_ASYNC, |
| 14204 | OK, |
| 14205 | kSecureServer, |
| 14206 | AUTH_ASYNC, |
| 14207 | OK, |
| 14208 | 3, |
| 14209 | 1, |
| 14210 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14211 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14212 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14213 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14214 | {__LINE__, |
| 14215 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14216 | AUTH_ASYNC, |
| 14217 | OK, |
| 14218 | kSecureServer, |
| 14219 | AUTH_ASYNC, |
| 14220 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14221 | 3, |
| 14222 | 1, |
| 14223 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14224 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14225 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14226 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14227 | {__LINE__, |
| 14228 | kProxy, |
| 14229 | AUTH_ASYNC, |
| 14230 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14231 | kSecureServer, |
| 14232 | AUTH_ASYNC, |
| 14233 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14234 | 4, |
| 14235 | 2, |
| 14236 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14237 | TestRound(kConnect, kProxyChallenge, OK), |
| 14238 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14239 | &kServerChallenge), |
| 14240 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14241 | }; |
| 14242 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14243 | for (const auto& test_config : test_configs) { |
| 14244 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 14245 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14246 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14247 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14248 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14249 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14250 | |
| 14251 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14252 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14253 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14254 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14255 | std::string auth_challenge = "Mock realm=proxy"; |
| 14256 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14257 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14258 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14259 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14260 | empty_ssl_info, origin, |
| 14261 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14262 | auth_handler->SetGenerateExpectation( |
| 14263 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14264 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14265 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 14266 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14267 | } |
| 14268 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 14269 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14270 | std::string auth_challenge = "Mock realm=server"; |
| 14271 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14272 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14273 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14274 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14275 | empty_ssl_info, origin, |
| 14276 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14277 | auth_handler->SetGenerateExpectation( |
| 14278 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14279 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14280 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14281 | |
| 14282 | // The second handler always succeeds. It should only be used where there |
| 14283 | // are multiple auth sessions for server auth in the same network |
| 14284 | // transaction using the same auth scheme. |
| 14285 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14286 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14287 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 14288 | empty_ssl_info, origin, |
| 14289 | NetLogWithSource()); |
| 14290 | second_handler->SetGenerateExpectation(true, OK); |
| 14291 | auth_factory->AddMockHandler(second_handler.release(), |
| 14292 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14293 | } |
| 14294 | if (test_config.proxy_url) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14295 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14296 | ProxyResolutionService::CreateFixed(test_config.proxy_url, |
| 14297 | TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14298 | } else { |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14299 | session_deps_.proxy_resolution_service = |
| 14300 | ProxyResolutionService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14301 | } |
| 14302 | |
| 14303 | HttpRequestInfo request; |
| 14304 | request.method = "GET"; |
| 14305 | request.url = GURL(test_config.server_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14306 | request.traffic_annotation = |
| 14307 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14308 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14309 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14310 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14311 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 14312 | |
| 14313 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 14314 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14315 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14316 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14317 | const TestRound& read_write_round = test_config.rounds[round]; |
| 14318 | |
| 14319 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14320 | mock_reads.back().push_back(read_write_round.read); |
| 14321 | mock_writes.back().push_back(read_write_round.write); |
| 14322 | |
| 14323 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 14324 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 14325 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14326 | mock_reads.push_back(std::vector<MockRead>()); |
| 14327 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14328 | } |
| 14329 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14330 | if (read_write_round.extra_read) { |
| 14331 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14332 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14333 | if (read_write_round.extra_write) { |
| 14334 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 14335 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14336 | |
| 14337 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14338 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14339 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14340 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14341 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14342 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14343 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14344 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14345 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14346 | mock_reads[i], mock_writes[i])); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14347 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 14348 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14349 | } |
| 14350 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 14351 | // Transaction must be created after DataProviders, so it's destroyed before |
| 14352 | // they are as well. |
| 14353 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 14354 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14355 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14356 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14357 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14358 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14359 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14360 | int rv; |
| 14361 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14362 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14363 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14364 | rv = trans.RestartWithAuth( |
| 14365 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14366 | } |
| 14367 | if (rv == ERR_IO_PENDING) |
| 14368 | rv = callback.WaitForResult(); |
| 14369 | |
| 14370 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14371 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14372 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 14373 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14374 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 14375 | continue; |
| 14376 | } |
| 14377 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14378 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14379 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14380 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14381 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14382 | } |
| 14383 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 14384 | } |
| 14385 | } |
| 14386 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14387 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14388 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14389 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14390 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14391 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14392 | session_deps_.proxy_resolution_service = |
| 14393 | ProxyResolutionService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14394 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14395 | |
| 14396 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14397 | auth_handler->set_connection_based(true); |
| 14398 | std::string auth_challenge = "Mock realm=server"; |
| 14399 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14400 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14401 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14402 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14403 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14404 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14405 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14406 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14407 | int rv = OK; |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 14408 | const HttpResponseInfo* response = nullptr; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14409 | HttpRequestInfo request; |
| 14410 | request.method = "GET"; |
| 14411 | request.url = origin; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14412 | request.traffic_annotation = |
| 14413 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14414 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14415 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14416 | |
| 14417 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 14418 | // to validate that the TCP socket is not released to the pool between |
| 14419 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14420 | HttpNetworkSessionPeer session_peer(session.get()); |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 14421 | CommonConnectJobParams common_connect_job_params( |
| 14422 | session->CreateCommonConnectJobParams()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14423 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
Tarun Bansal | a763509 | 2019-02-20 10:00:59 | [diff] [blame] | 14424 | 50, // Max sockets for pool |
| 14425 | 1, // Max sockets per group |
| 14426 | base::TimeDelta::FromSeconds(10), // unused_idle_socket_timeout |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 14427 | &common_connect_job_params, session_deps_.ssl_config_service.get()); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14428 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 14429 | mock_pool_manager->SetSocketPool(ProxyServer::Direct(), |
| 14430 | base::WrapUnique(transport_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14431 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14432 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14433 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14434 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14435 | |
| 14436 | const MockWrite kGet( |
| 14437 | "GET / HTTP/1.1\r\n" |
| 14438 | "Host: www.example.com\r\n" |
| 14439 | "Connection: keep-alive\r\n\r\n"); |
| 14440 | const MockWrite kGetAuth( |
| 14441 | "GET / HTTP/1.1\r\n" |
| 14442 | "Host: www.example.com\r\n" |
| 14443 | "Connection: keep-alive\r\n" |
| 14444 | "Authorization: auth_token\r\n\r\n"); |
| 14445 | |
| 14446 | const MockRead kServerChallenge( |
| 14447 | "HTTP/1.1 401 Unauthorized\r\n" |
| 14448 | "WWW-Authenticate: Mock realm=server\r\n" |
| 14449 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14450 | "Content-Length: 14\r\n\r\n" |
| 14451 | "Unauthorized\r\n"); |
| 14452 | const MockRead kSuccess( |
| 14453 | "HTTP/1.1 200 OK\r\n" |
| 14454 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14455 | "Content-Length: 3\r\n\r\n" |
| 14456 | "Yes"); |
| 14457 | |
| 14458 | MockWrite writes[] = { |
| 14459 | // First round |
| 14460 | kGet, |
| 14461 | // Second round |
| 14462 | kGetAuth, |
| 14463 | // Third round |
| 14464 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14465 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14466 | kGetAuth, |
| 14467 | // Competing request |
| 14468 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14469 | }; |
| 14470 | MockRead reads[] = { |
| 14471 | // First round |
| 14472 | kServerChallenge, |
| 14473 | // Second round |
| 14474 | kServerChallenge, |
| 14475 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14476 | kServerChallenge, |
| 14477 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14478 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14479 | // Competing response |
| 14480 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14481 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14482 | StaticSocketDataProvider data_provider(reads, writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14483 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14484 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 14485 | const ClientSocketPool::GroupId kSocketGroup( |
| 14486 | HostPortPair("www.example.com", 80), ClientSocketPool::SocketType::kHttp, |
| 14487 | false /* privacy_mode */); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14488 | |
| 14489 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14490 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14491 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14492 | if (rv == ERR_IO_PENDING) |
| 14493 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14494 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14495 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14496 | ASSERT_TRUE(response); |
| 14497 | EXPECT_TRUE(response->auth_challenge); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14498 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14499 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14500 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14501 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14502 | // In between rounds, another request comes in for the same domain. |
| 14503 | // It should not be able to grab the TCP socket that trans has already |
| 14504 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14505 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14506 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14507 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 14508 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14509 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14510 | // callback_compete.WaitForResult at this point would stall forever, |
| 14511 | // since the HttpNetworkTransaction does not release the request back to |
| 14512 | // the pool until after authentication completes. |
| 14513 | |
| 14514 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14515 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14516 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14517 | if (rv == ERR_IO_PENDING) |
| 14518 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14519 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14520 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14521 | ASSERT_TRUE(response); |
| 14522 | EXPECT_FALSE(response->auth_challenge); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14523 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14524 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14525 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14526 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14527 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14528 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14529 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14530 | if (rv == ERR_IO_PENDING) |
| 14531 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14532 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14533 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14534 | ASSERT_TRUE(response); |
| 14535 | EXPECT_FALSE(response->auth_challenge); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14536 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14537 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14538 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14539 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14540 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14541 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14542 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14543 | if (rv == ERR_IO_PENDING) |
| 14544 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14545 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14546 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14547 | ASSERT_TRUE(response); |
| 14548 | EXPECT_FALSE(response->auth_challenge); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14549 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14550 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14551 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 14552 | // auth handler should transition to a DONE state in concert with the remote |
| 14553 | // server. But that's not something we can test here with a mock handler. |
| 14554 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 14555 | auth_handler->state()); |
| 14556 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14557 | // Read the body since the fourth round was successful. This will also |
| 14558 | // release the socket back to the pool. |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 14559 | scoped_refptr<IOBufferWithSize> io_buf = |
| 14560 | base::MakeRefCounted<IOBufferWithSize>(50); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14561 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14562 | if (rv == ERR_IO_PENDING) |
| 14563 | rv = callback.WaitForResult(); |
| 14564 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14565 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14566 | EXPECT_EQ(0, rv); |
| 14567 | // There are still 0 idle sockets, since the trans_compete transaction |
| 14568 | // will be handed it immediately after trans releases it to the group. |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14569 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14570 | |
| 14571 | // The competing request can now finish. Wait for the headers and then |
| 14572 | // read the body. |
| 14573 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14574 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14575 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14576 | if (rv == ERR_IO_PENDING) |
| 14577 | rv = callback.WaitForResult(); |
| 14578 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14579 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14580 | EXPECT_EQ(0, rv); |
| 14581 | |
| 14582 | // Finally, the socket is released to the group. |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14583 | EXPECT_EQ(1u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14584 | } |
| 14585 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14586 | // This tests the case that a request is issued via http instead of spdy after |
| 14587 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14588 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14589 | HttpRequestInfo request; |
| 14590 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14591 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14592 | request.traffic_annotation = |
| 14593 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14594 | |
| 14595 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14596 | MockWrite( |
| 14597 | "GET / HTTP/1.1\r\n" |
| 14598 | "Host: www.example.org\r\n" |
| 14599 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14600 | }; |
| 14601 | |
| 14602 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14603 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 14604 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14605 | MockRead("\r\n"), |
| 14606 | MockRead("hello world"), |
| 14607 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14608 | }; |
| 14609 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14610 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14611 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14612 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14613 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14614 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14615 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14616 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14617 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14618 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14619 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14620 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14621 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14622 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14623 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14624 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14625 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14626 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14627 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14628 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14629 | ASSERT_TRUE(response); |
| 14630 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14631 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14632 | |
| 14633 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14634 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14635 | EXPECT_EQ("hello world", response_data); |
| 14636 | |
| 14637 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14638 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14639 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14640 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 14641 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 14642 | // immediate server closing of the socket. |
| 14643 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14644 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14645 | HttpRequestInfo request; |
| 14646 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14647 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14648 | request.traffic_annotation = |
| 14649 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14650 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14651 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14652 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14653 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14654 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14655 | spdy::SpdySerializedFrame req( |
| 14656 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14657 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14658 | |
| 14659 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14660 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14661 | }; |
| 14662 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14663 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14664 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14665 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14666 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14667 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14668 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14669 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14670 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14671 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14672 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14673 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14674 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14675 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14676 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 14677 | // it gets it. This is needed since the auth handler may get destroyed |
| 14678 | // before we get a chance to query it. |
| 14679 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 14680 | public: |
| 14681 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 14682 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 14683 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14684 | |
| 14685 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14686 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 14687 | const HttpRequestInfo* request, |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 14688 | CompletionOnceCallback callback, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14689 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14690 | *url_ = request->url; |
| 14691 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 14692 | credentials, request, std::move(callback), auth_token); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14693 | } |
| 14694 | |
| 14695 | private: |
| 14696 | GURL* url_; |
| 14697 | }; |
| 14698 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14699 | // Test that if we cancel the transaction as the connection is completing, that |
| 14700 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14701 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14702 | // Setup everything about the connection to complete synchronously, so that |
| 14703 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 14704 | // for is the callback from the HttpStreamRequest. |
| 14705 | // Then cancel the transaction. |
| 14706 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 14707 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14708 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14709 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 14710 | MockRead(SYNCHRONOUS, "hello world"), |
| 14711 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14712 | }; |
| 14713 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14714 | HttpRequestInfo request; |
| 14715 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14716 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14717 | request.traffic_annotation = |
| 14718 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14719 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14720 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14721 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14722 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14723 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14724 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14725 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14726 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14727 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14728 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14729 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14730 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14731 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14732 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14733 | trans.reset(); // Cancel the transaction here. |
| 14734 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14735 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 14736 | } |
| 14737 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14738 | // Test that if a transaction is cancelled after receiving the headers, the |
| 14739 | // stream is drained properly and added back to the socket pool. The main |
| 14740 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 14741 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 14742 | // deleted. |
| 14743 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14744 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14745 | MockRead data_reads[] = { |
| 14746 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 14747 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 14748 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 14749 | MockRead(ASYNC, "1"), |
| 14750 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 14751 | // HttpNetworkTransaction has been deleted. |
| 14752 | MockRead(ASYNC, "2"), |
| 14753 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 14754 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14755 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14756 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14757 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14758 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14759 | |
| 14760 | { |
| 14761 | HttpRequestInfo request; |
| 14762 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14763 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14764 | request.traffic_annotation = |
| 14765 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14766 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14767 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14768 | TestCompletionCallback callback; |
| 14769 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14770 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14771 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14772 | callback.WaitForResult(); |
| 14773 | |
| 14774 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14775 | ASSERT_TRUE(response); |
| 14776 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14777 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14778 | |
| 14779 | // The transaction and HttpRequestInfo are deleted. |
| 14780 | } |
| 14781 | |
| 14782 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14783 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14784 | |
| 14785 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14786 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14787 | } |
| 14788 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14789 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14790 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14791 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14792 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14793 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14794 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14795 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14796 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14797 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14798 | HttpRequestInfo request; |
| 14799 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14800 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14801 | request.traffic_annotation = |
| 14802 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14803 | |
| 14804 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14805 | MockWrite( |
| 14806 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 14807 | "Host: www.example.org\r\n" |
| 14808 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14809 | }; |
| 14810 | |
| 14811 | MockRead data_reads1[] = { |
| 14812 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14813 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14814 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14815 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14816 | }; |
| 14817 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14818 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14819 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14820 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14821 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14822 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14823 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14824 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14825 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14826 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 14827 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14828 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14829 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14830 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14831 | |
| 14832 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14833 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14834 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14835 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14836 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14837 | |
| 14838 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14839 | EXPECT_EQ(200, response->headers->response_code()); |
| 14840 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14841 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14842 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14843 | HostPortPair::FromString("myproxy:70")), |
| 14844 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14845 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14846 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14847 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14848 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14849 | |
| 14850 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14851 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14852 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14853 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14854 | } |
| 14855 | |
| 14856 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14857 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14858 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14859 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14860 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14861 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14862 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14863 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14864 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14865 | HttpRequestInfo request; |
| 14866 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14867 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14868 | request.traffic_annotation = |
| 14869 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14870 | |
| 14871 | // Since we have proxy, should try to establish tunnel. |
| 14872 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14873 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14874 | "Host: www.example.org:443\r\n" |
| 14875 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14876 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14877 | MockWrite("GET / HTTP/1.1\r\n" |
| 14878 | "Host: www.example.org\r\n" |
| 14879 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14880 | }; |
| 14881 | |
| 14882 | MockRead data_reads1[] = { |
| 14883 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14884 | |
| 14885 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14886 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14887 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14888 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14889 | }; |
| 14890 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14891 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14892 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14893 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14894 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14895 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14896 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14897 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14898 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14899 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14900 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14901 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 14902 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14903 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14904 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14905 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14906 | |
| 14907 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14908 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14909 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14910 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14911 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14912 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14913 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14914 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14915 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14916 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14917 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14918 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14919 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14920 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14921 | |
| 14922 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14923 | EXPECT_EQ(200, response->headers->response_code()); |
| 14924 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14925 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14926 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14927 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14928 | HostPortPair::FromString("myproxy:70")), |
| 14929 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14930 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14931 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14932 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14933 | |
| 14934 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14935 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14936 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14937 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14938 | } |
| 14939 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14940 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 14941 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14942 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14943 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14944 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14945 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14946 | BoundTestNetLog log; |
| 14947 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14948 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14949 | |
| 14950 | HttpRequestInfo request; |
| 14951 | request.method = "GET"; |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14952 | request.url = GURL("https://[::2]:443/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14953 | request.traffic_annotation = |
| 14954 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14955 | |
| 14956 | // Since we have proxy, should try to establish tunnel. |
| 14957 | MockWrite data_writes1[] = { |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14958 | MockWrite("CONNECT [::2]:443 HTTP/1.1\r\n" |
| 14959 | "Host: [::2]:443\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14960 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 14961 | |
| 14962 | MockWrite("GET / HTTP/1.1\r\n" |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14963 | "Host: [::2]\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14964 | "Connection: keep-alive\r\n\r\n"), |
| 14965 | }; |
| 14966 | |
| 14967 | MockRead data_reads1[] = { |
| 14968 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14969 | |
| 14970 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14971 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14972 | MockRead("Content-Length: 100\r\n\r\n"), |
| 14973 | MockRead(SYNCHRONOUS, OK), |
| 14974 | }; |
| 14975 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14976 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14977 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14978 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14979 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14980 | |
| 14981 | TestCompletionCallback callback1; |
| 14982 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14983 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14984 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14985 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14986 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14987 | |
| 14988 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14989 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14990 | TestNetLogEntry::List entries; |
| 14991 | log.GetEntries(&entries); |
| 14992 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14993 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14994 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14995 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14996 | entries, pos, |
| 14997 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14998 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14999 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15000 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15001 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15002 | |
| 15003 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 15004 | EXPECT_EQ(200, response->headers->response_code()); |
| 15005 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 15006 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 15007 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 15008 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 15009 | HostPortPair::FromString("myproxy:70")), |
| 15010 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15011 | |
| 15012 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15013 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15014 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 15015 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 15016 | } |
| 15017 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15018 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 15019 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15020 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15021 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 15022 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15023 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15024 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15025 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15026 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15027 | HttpRequestInfo request; |
| 15028 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15029 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15030 | request.traffic_annotation = |
| 15031 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15032 | |
| 15033 | // Since we have proxy, should try to establish tunnel. |
| 15034 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15035 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15036 | "Host: www.example.org:443\r\n" |
| 15037 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15038 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15039 | MockWrite("GET / HTTP/1.1\r\n" |
| 15040 | "Host: www.example.org\r\n" |
| 15041 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15042 | }; |
| 15043 | |
| 15044 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15045 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15046 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15047 | }; |
| 15048 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15049 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15050 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15051 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15052 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15053 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15054 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15055 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15056 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 15057 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15058 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15059 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15060 | |
| 15061 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15062 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 15063 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 15064 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15065 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15066 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 15067 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15068 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 15069 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15070 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 15071 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15072 | } |
| 15073 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15074 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15075 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15076 | spdy::SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15077 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15078 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15079 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15080 | spdy::SpdySerializedFrame resp( |
| 15081 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15082 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15083 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15084 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15085 | }; |
| 15086 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15087 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15088 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15089 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15090 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15091 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15092 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15093 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15094 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15095 | |
| 15096 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15097 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 15098 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 15099 | PRIVACY_MODE_DISABLED, |
| 15100 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 15101 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 15102 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15103 | |
| 15104 | HttpRequestInfo request; |
| 15105 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15106 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15107 | request.traffic_annotation = |
| 15108 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15109 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15110 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15111 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15112 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15113 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15114 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15115 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15116 | } |
| 15117 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15118 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15119 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 15120 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15121 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15122 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15123 | request_info.url = GURL("https://www.example.com/"); |
| 15124 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15125 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15126 | request_info.traffic_annotation = |
| 15127 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15128 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15129 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15130 | MockWrite data_writes[] = { |
| 15131 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15132 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15133 | StaticSocketDataProvider data(base::span<MockRead>(), data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15134 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15135 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15136 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15137 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15138 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15139 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15140 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15141 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15142 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15143 | rv = callback.WaitForResult(); |
| 15144 | ASSERT_EQ(error, rv); |
| 15145 | } |
| 15146 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15147 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15148 | // Just check a grab bag of cert errors. |
| 15149 | static const int kErrors[] = { |
| 15150 | ERR_CERT_COMMON_NAME_INVALID, |
| 15151 | ERR_CERT_AUTHORITY_INVALID, |
| 15152 | ERR_CERT_DATE_INVALID, |
| 15153 | }; |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 15154 | for (size_t i = 0; i < base::size(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15155 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 15156 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15157 | } |
| 15158 | } |
| 15159 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15160 | // Ensure that a client certificate is removed from the SSL client auth |
| 15161 | // cache when: |
| 15162 | // 1) No proxy is involved. |
| 15163 | // 2) TLS False Start is disabled. |
| 15164 | // 3) The initial TLS handshake requests a client certificate. |
| 15165 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15166 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15167 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15168 | request_info.url = GURL("https://www.example.com/"); |
| 15169 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15170 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15171 | request_info.traffic_annotation = |
| 15172 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15173 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15174 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15175 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15176 | |
| 15177 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 15178 | // CertificateRequest is received for the first time, the handshake will |
| 15179 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15180 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15181 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15182 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15183 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15184 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15185 | |
| 15186 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 15187 | // False Start is not being used, the result of the SSL handshake will be |
| 15188 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 15189 | // matches the result of a server sending a handshake_failure alert, |
| 15190 | // rather than a Finished message, because it requires a client |
| 15191 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15192 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15193 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15194 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15195 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15196 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15197 | |
| 15198 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 15199 | // connection to a server fails during an SSL handshake, |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15200 | // HttpNetworkTransaction will attempt to fallback to TLSv1.2 if the previous |
| 15201 | // connection was attempted with TLSv1.3. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15202 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15203 | // requiring a client certificate, this fallback handshake should also |
| 15204 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15205 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15206 | ssl_data3.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15207 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15208 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15209 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15210 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15211 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15212 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 15213 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 15214 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 15215 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15216 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15217 | // requiring a client certificate, this fallback handshake should also |
| 15218 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15219 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15220 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15221 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15222 | StaticSocketDataProvider data4; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15223 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15224 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15225 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15226 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15227 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15228 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15229 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15230 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15231 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15232 | |
| 15233 | // Complete the SSL handshake, which should abort due to requiring a |
| 15234 | // client certificate. |
| 15235 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15236 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15237 | |
| 15238 | // Indicate that no certificate should be supplied. From the perspective |
| 15239 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15240 | // certificate, so this is the same as supply a |
| 15241 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15242 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15243 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15244 | |
| 15245 | // Ensure the certificate was added to the client auth cache before |
| 15246 | // allowing the connection to continue restarting. |
| 15247 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15248 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15249 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15250 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15251 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15252 | |
| 15253 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15254 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15255 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15256 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15257 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15258 | |
| 15259 | // Ensure that the client certificate is removed from the cache on a |
| 15260 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15261 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15262 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15263 | } |
| 15264 | |
| 15265 | // Ensure that a client certificate is removed from the SSL client auth |
| 15266 | // cache when: |
| 15267 | // 1) No proxy is involved. |
| 15268 | // 2) TLS False Start is enabled. |
| 15269 | // 3) The initial TLS handshake requests a client certificate. |
| 15270 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15271 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15272 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15273 | request_info.url = GURL("https://www.example.com/"); |
| 15274 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15275 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15276 | request_info.traffic_annotation = |
| 15277 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15278 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15279 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15280 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15281 | |
| 15282 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 15283 | // return successfully after reading up to the peer's Certificate message. |
| 15284 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 15285 | // enqueue application data to be sent in the same packet as the |
| 15286 | // ChangeCipherSpec and Finished messages. |
| 15287 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 15288 | // called, which expects to process the peer's ChangeCipherSpec and |
| 15289 | // Finished messages. If there was an error negotiating with the peer, |
| 15290 | // such as due to the peer requiring a client certificate when none was |
| 15291 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 15292 | // called. |
| 15293 | |
| 15294 | // Like the non-False Start case, when a client certificate is requested by |
| 15295 | // the peer, the handshake is aborted during the Connect() call. |
| 15296 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15297 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15298 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15299 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15300 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15301 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15302 | |
| 15303 | // When a client certificate is supplied, Connect() will not be aborted |
| 15304 | // when the peer requests the certificate. Instead, the handshake will |
| 15305 | // artificially succeed, allowing the caller to write the HTTP request to |
| 15306 | // the socket. The handshake messages are not processed until Read() is |
| 15307 | // called, which then detects that the handshake was aborted, due to the |
| 15308 | // peer sending a handshake_failure because it requires a client |
| 15309 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15310 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15311 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15312 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15313 | MockRead data2_reads[] = { |
| 15314 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15315 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15316 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15317 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15318 | |
| 15319 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15320 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 15321 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15322 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15323 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15324 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15325 | StaticSocketDataProvider data3(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15326 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15327 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15328 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 15329 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15330 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15331 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15332 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15333 | StaticSocketDataProvider data4(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15334 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15335 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15336 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15337 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15338 | ssl_data5.cert_request_info = cert_request.get(); |
| 15339 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15340 | StaticSocketDataProvider data5(data2_reads, base::span<MockWrite>()); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15341 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 15342 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15343 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15344 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15345 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15346 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15347 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15348 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15349 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15350 | |
| 15351 | // Complete the SSL handshake, which should abort due to requiring a |
| 15352 | // client certificate. |
| 15353 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15354 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15355 | |
| 15356 | // Indicate that no certificate should be supplied. From the perspective |
| 15357 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15358 | // certificate, so this is the same as supply a |
| 15359 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15360 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15361 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15362 | |
| 15363 | // Ensure the certificate was added to the client auth cache before |
| 15364 | // allowing the connection to continue restarting. |
| 15365 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15366 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15367 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15368 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15369 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15370 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15371 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15372 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15373 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15374 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15375 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15376 | |
| 15377 | // Ensure that the client certificate is removed from the cache on a |
| 15378 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15379 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15380 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15381 | } |
| 15382 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15383 | // Ensure that a client certificate is removed from the SSL client auth |
| 15384 | // cache when: |
| 15385 | // 1) An HTTPS proxy is involved. |
| 15386 | // 3) The HTTPS proxy requests a client certificate. |
| 15387 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 15388 | // proxy. |
| 15389 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 15390 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15391 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15392 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 15393 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15394 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15395 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15396 | |
| 15397 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15398 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15399 | |
| 15400 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 15401 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 15402 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 15403 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15404 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15405 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15406 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15407 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15408 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15409 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15410 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15411 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15412 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15413 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15414 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15415 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15416 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 15417 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15418 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15419 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15420 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15421 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15422 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15423 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15424 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15425 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15426 | requests[0].url = GURL("https://www.example.com/"); |
| 15427 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15428 | requests[0].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15429 | requests[0].traffic_annotation = |
| 15430 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15431 | |
| 15432 | requests[1].url = GURL("http://www.example.com/"); |
| 15433 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15434 | requests[1].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15435 | requests[1].traffic_annotation = |
| 15436 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15437 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 15438 | for (size_t i = 0; i < base::size(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15439 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15440 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15441 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15442 | |
| 15443 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15444 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15445 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15446 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15447 | |
| 15448 | // Complete the SSL handshake, which should abort due to requiring a |
| 15449 | // client certificate. |
| 15450 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15451 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15452 | |
| 15453 | // Indicate that no certificate should be supplied. From the perspective |
| 15454 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15455 | // certificate, so this is the same as supply a |
| 15456 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15457 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15458 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15459 | |
| 15460 | // Ensure the certificate was added to the client auth cache before |
| 15461 | // allowing the connection to continue restarting. |
| 15462 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15463 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15464 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15465 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15466 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15467 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 15468 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15469 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15470 | HostPortPair("www.example.com", 443), &client_cert, |
| 15471 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15472 | |
| 15473 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 15474 | // then consume ssl_data3, which should also fail. The result code is |
| 15475 | // checked against what ssl_data3 should return. |
| 15476 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15477 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15478 | |
| 15479 | // Now that the new handshake has failed, ensure that the client |
| 15480 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15481 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15482 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15483 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15484 | HostPortPair("www.example.com", 443), &client_cert, |
| 15485 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15486 | } |
| 15487 | } |
| 15488 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15489 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15490 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15491 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15492 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15493 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15494 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15495 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15496 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15497 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15498 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15499 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15500 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15501 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15502 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15503 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15504 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15505 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15506 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15507 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15508 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15509 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15510 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15511 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15512 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15513 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15514 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15515 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15516 | }; |
| 15517 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15518 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15519 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15520 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15521 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15522 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15523 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15524 | HttpRequestInfo request1; |
| 15525 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15526 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15527 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15528 | request1.traffic_annotation = |
| 15529 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15530 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15531 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15532 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15533 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15534 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15535 | |
| 15536 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15537 | ASSERT_TRUE(response); |
| 15538 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15539 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15540 | |
| 15541 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15542 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15543 | EXPECT_EQ("hello!", response_data); |
| 15544 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15545 | // Preload mail.example.com into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15546 | rv = session_deps_.host_resolver->LoadIntoCache( |
| 15547 | HostPortPair("mail.example.com", 443), base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15548 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15549 | |
| 15550 | HttpRequestInfo request2; |
| 15551 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15552 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15553 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15554 | request2.traffic_annotation = |
| 15555 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15556 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15557 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15558 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15559 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15560 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15561 | |
| 15562 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15563 | ASSERT_TRUE(response); |
| 15564 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15565 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15566 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15567 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15568 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15569 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15570 | } |
| 15571 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15572 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15573 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15574 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15575 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15576 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15577 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15578 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15579 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15580 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15581 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15582 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15583 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15584 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15585 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15586 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15587 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15588 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15589 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15590 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15591 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15592 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15593 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15594 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15595 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15596 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15597 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15598 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15599 | }; |
| 15600 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15601 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15602 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15603 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15604 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15605 | |
| 15606 | TestCompletionCallback callback; |
| 15607 | HttpRequestInfo request1; |
| 15608 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15609 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15610 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15611 | request1.traffic_annotation = |
| 15612 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15613 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15614 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15615 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15616 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15617 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15618 | |
| 15619 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15620 | ASSERT_TRUE(response); |
| 15621 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15622 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15623 | |
| 15624 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15625 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15626 | EXPECT_EQ("hello!", response_data); |
| 15627 | |
| 15628 | HttpRequestInfo request2; |
| 15629 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15630 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15631 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15632 | request2.traffic_annotation = |
| 15633 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15634 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15635 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15636 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15637 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15638 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15639 | |
| 15640 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15641 | ASSERT_TRUE(response); |
| 15642 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15643 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15644 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15645 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15646 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15647 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15648 | } |
| 15649 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15650 | // Regression test for https://crbug.com/546991. |
| 15651 | // The server might not be able to serve an IP pooled request, and might send a |
| 15652 | // 421 Misdirected Request response status to indicate this. |
| 15653 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 15654 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 15655 | // Two hosts resolve to the same IP address. |
| 15656 | const std::string ip_addr = "1.2.3.4"; |
| 15657 | IPAddress ip; |
| 15658 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 15659 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15660 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15661 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15662 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 15663 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 15664 | |
| 15665 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15666 | |
| 15667 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15668 | spdy::SpdySerializedFrame req1( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15669 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 15670 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15671 | spdy::SpdySerializedFrame req2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15672 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15673 | spdy::SpdySerializedFrame rst( |
| 15674 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15675 | MockWrite writes1[] = { |
| 15676 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 15677 | CreateMockWrite(rst, 6), |
| 15678 | }; |
| 15679 | |
| 15680 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15681 | spdy::SpdySerializedFrame resp1( |
| 15682 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15683 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15684 | spdy::SpdyHeaderBlock response_headers; |
| 15685 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 15686 | spdy::SpdySerializedFrame resp2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15687 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 15688 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 15689 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 15690 | |
| 15691 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15692 | SequencedSocketData data1(connect1, reads1, writes1); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15693 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15694 | |
| 15695 | AddSSLSocketData(); |
| 15696 | |
| 15697 | // Retry the second request on a second connection. |
| 15698 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15699 | spdy::SpdySerializedFrame req3( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15700 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 15701 | MockWrite writes2[] = { |
| 15702 | CreateMockWrite(req3, 0), |
| 15703 | }; |
| 15704 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15705 | spdy::SpdySerializedFrame resp3( |
| 15706 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15707 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15708 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 15709 | MockRead(ASYNC, 0, 3)}; |
| 15710 | |
| 15711 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15712 | SequencedSocketData data2(connect2, reads2, writes2); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15713 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15714 | |
| 15715 | AddSSLSocketData(); |
| 15716 | |
| 15717 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15718 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 15719 | HostPortPair("mail.example.com", 443), base::nullopt); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15720 | EXPECT_THAT(rv, IsOk()); |
| 15721 | |
| 15722 | HttpRequestInfo request1; |
| 15723 | request1.method = "GET"; |
| 15724 | request1.url = GURL("https://www.example.org/"); |
| 15725 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15726 | request1.traffic_annotation = |
| 15727 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15728 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15729 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15730 | TestCompletionCallback callback; |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15731 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 15732 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15733 | rv = callback.WaitForResult(); |
| 15734 | EXPECT_THAT(rv, IsOk()); |
| 15735 | |
| 15736 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 15737 | ASSERT_TRUE(response); |
| 15738 | ASSERT_TRUE(response->headers); |
| 15739 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15740 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15741 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15742 | std::string response_data; |
| 15743 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 15744 | EXPECT_EQ("hello!", response_data); |
| 15745 | |
| 15746 | HttpRequestInfo request2; |
| 15747 | request2.method = "GET"; |
| 15748 | request2.url = GURL("https://mail.example.org/"); |
| 15749 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15750 | request2.traffic_annotation = |
| 15751 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15752 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15753 | |
| 15754 | BoundTestNetLog log; |
| 15755 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 15756 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15757 | rv = callback.WaitForResult(); |
| 15758 | EXPECT_THAT(rv, IsOk()); |
| 15759 | |
| 15760 | response = trans2.GetResponseInfo(); |
| 15761 | ASSERT_TRUE(response); |
| 15762 | ASSERT_TRUE(response->headers); |
| 15763 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15764 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15765 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15766 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 15767 | EXPECT_EQ("hello!", response_data); |
| 15768 | |
| 15769 | TestNetLogEntry::List entries; |
| 15770 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15771 | ExpectLogContainsSomewhere( |
| 15772 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15773 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15774 | } |
| 15775 | |
| 15776 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 15777 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 15778 | // portions of the response. |
| 15779 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 15780 | // Two hosts resolve to the same IP address. |
| 15781 | const std::string ip_addr = "1.2.3.4"; |
| 15782 | IPAddress ip; |
| 15783 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 15784 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15785 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15786 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15787 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 15788 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 15789 | |
| 15790 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15791 | |
| 15792 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15793 | spdy::SpdySerializedFrame req1( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15794 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 15795 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15796 | spdy::SpdySerializedFrame req2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15797 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15798 | spdy::SpdySerializedFrame rst( |
| 15799 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15800 | MockWrite writes1[] = { |
| 15801 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 15802 | CreateMockWrite(rst, 6), |
| 15803 | }; |
| 15804 | |
| 15805 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15806 | spdy::SpdySerializedFrame resp1( |
| 15807 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15808 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15809 | spdy::SpdyHeaderBlock response_headers; |
| 15810 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 15811 | spdy::SpdySerializedFrame resp2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15812 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 15813 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 15814 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 15815 | |
| 15816 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15817 | SequencedSocketData data1(connect1, reads1, writes1); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15818 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15819 | |
| 15820 | AddSSLSocketData(); |
| 15821 | |
| 15822 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 15823 | // Retry again. |
| 15824 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15825 | spdy::SpdySerializedFrame req3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15826 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 15827 | MockWrite writes2[] = { |
| 15828 | CreateMockWrite(req3, 0), |
| 15829 | }; |
| 15830 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15831 | spdy::SpdySerializedFrame resp3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15832 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15833 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15834 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 15835 | MockRead(ASYNC, 0, 3)}; |
| 15836 | |
| 15837 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15838 | SequencedSocketData data2(connect2, reads2, writes2); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15839 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15840 | |
| 15841 | AddSSLSocketData(); |
| 15842 | |
| 15843 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15844 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 15845 | HostPortPair("mail.example.com", 443), base::nullopt); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15846 | EXPECT_THAT(rv, IsOk()); |
| 15847 | |
| 15848 | HttpRequestInfo request1; |
| 15849 | request1.method = "GET"; |
| 15850 | request1.url = GURL("https://www.example.org/"); |
| 15851 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15852 | request1.traffic_annotation = |
| 15853 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15854 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15855 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15856 | TestCompletionCallback callback; |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15857 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 15858 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15859 | rv = callback.WaitForResult(); |
| 15860 | EXPECT_THAT(rv, IsOk()); |
| 15861 | |
| 15862 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 15863 | ASSERT_TRUE(response); |
| 15864 | ASSERT_TRUE(response->headers); |
| 15865 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15866 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15867 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15868 | std::string response_data; |
| 15869 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 15870 | EXPECT_EQ("hello!", response_data); |
| 15871 | |
| 15872 | HttpRequestInfo request2; |
| 15873 | request2.method = "GET"; |
| 15874 | request2.url = GURL("https://mail.example.org/"); |
| 15875 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15876 | request2.traffic_annotation = |
| 15877 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15878 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15879 | |
| 15880 | BoundTestNetLog log; |
| 15881 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 15882 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15883 | rv = callback.WaitForResult(); |
| 15884 | EXPECT_THAT(rv, IsOk()); |
| 15885 | |
| 15886 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 15887 | // caller. |
| 15888 | response = trans2.GetResponseInfo(); |
| 15889 | ASSERT_TRUE(response); |
| 15890 | ASSERT_TRUE(response->headers); |
| 15891 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 15892 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15893 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15894 | EXPECT_TRUE(response->ssl_info.cert); |
| 15895 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 15896 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15897 | } |
| 15898 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15899 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 15900 | UseIPConnectionPoolingWithHostCacheExpiration) { |
Eric Orth | 1da75de | 2019-02-20 21:10:34 | [diff] [blame] | 15901 | // Set up HostResolver to invalidate cached entries after 1 cached resolve. |
| 15902 | session_deps_.host_resolver = |
| 15903 | std::make_unique<MockCachingHostResolver>(1 /* cache_invalidation_num */); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15904 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15905 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15906 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15907 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15908 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15909 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15910 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15911 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15912 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15913 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15914 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15915 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15916 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15917 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15918 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15919 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15920 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15921 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15922 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15923 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15924 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15925 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15926 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15927 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15928 | }; |
| 15929 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15930 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15931 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15932 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15933 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15934 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15935 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15936 | HttpRequestInfo request1; |
| 15937 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15938 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15939 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15940 | request1.traffic_annotation = |
| 15941 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15942 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15943 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15944 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15945 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15946 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15947 | |
| 15948 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15949 | ASSERT_TRUE(response); |
| 15950 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15951 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15952 | |
| 15953 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15954 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15955 | EXPECT_EQ("hello!", response_data); |
| 15956 | |
| 15957 | // Preload cache entries into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15958 | rv = session_deps_.host_resolver->LoadIntoCache( |
| 15959 | HostPortPair("mail.example.com", 443), base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15960 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15961 | |
| 15962 | HttpRequestInfo request2; |
| 15963 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15964 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15965 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15966 | request2.traffic_annotation = |
| 15967 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15968 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15969 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15970 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15971 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15972 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15973 | |
| 15974 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15975 | ASSERT_TRUE(response); |
| 15976 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15977 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15978 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15979 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15980 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15981 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15982 | } |
| 15983 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15984 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15985 | const std::string https_url = "https://www.example.org:8080/"; |
| 15986 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15987 | |
| 15988 | // SPDY GET for HTTPS URL |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15989 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15990 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15991 | |
| 15992 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15993 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15994 | }; |
| 15995 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15996 | spdy::SpdySerializedFrame resp1( |
| 15997 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15998 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15999 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16000 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16001 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16002 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16003 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 16004 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16005 | |
| 16006 | // HTTP GET for the HTTP URL |
| 16007 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 16008 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 16009 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16010 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 16011 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16012 | }; |
| 16013 | |
| 16014 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 16015 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 16016 | MockRead(ASYNC, 2, "hello"), |
| 16017 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16018 | }; |
| 16019 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16020 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16021 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16022 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16023 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16024 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16025 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 16026 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16027 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16028 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16029 | |
| 16030 | // Start the first transaction to set up the SpdySession |
| 16031 | HttpRequestInfo request1; |
| 16032 | request1.method = "GET"; |
| 16033 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16034 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16035 | request1.traffic_annotation = |
| 16036 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16037 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16038 | TestCompletionCallback callback1; |
| 16039 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16040 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16041 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16042 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16043 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16044 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16045 | |
| 16046 | // Now, start the HTTP request |
| 16047 | HttpRequestInfo request2; |
| 16048 | request2.method = "GET"; |
| 16049 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16050 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16051 | request2.traffic_annotation = |
| 16052 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16053 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16054 | TestCompletionCallback callback2; |
| 16055 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16056 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16057 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16058 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16059 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16060 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16061 | } |
| 16062 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16063 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 16064 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16065 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16066 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 16067 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16068 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16069 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16070 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16071 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16072 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16073 | |
| 16074 | // No data should be read from the alternative, because HTTP/1.1 is |
| 16075 | // negotiated. |
| 16076 | StaticSocketDataProvider data; |
| 16077 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16078 | |
| 16079 | // 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] | 16080 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16081 | // mocked. This way the request relies on the alternate Job. |
| 16082 | StaticSocketDataProvider data_refused; |
| 16083 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 16084 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 16085 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16086 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16087 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16088 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16089 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16090 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16091 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16092 | http_server_properties->SetHttp2AlternativeService( |
| 16093 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16094 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16095 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16096 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16097 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16098 | request.url = GURL("https://www.example.org:443"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16099 | request.traffic_annotation = |
| 16100 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16101 | TestCompletionCallback callback; |
| 16102 | |
| 16103 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16104 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16105 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16106 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16107 | } |
| 16108 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16109 | // 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] | 16110 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16111 | // succeeds, the request should succeed, even if the latter fails because |
| 16112 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16113 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16114 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 16115 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16116 | |
| 16117 | // Negotiate HTTP/1.1 with alternative. |
| 16118 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16119 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16120 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 16121 | |
| 16122 | // No data should be read from the alternative, because HTTP/1.1 is |
| 16123 | // negotiated. |
| 16124 | StaticSocketDataProvider data; |
| 16125 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16126 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16127 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16128 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16129 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16130 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 16131 | |
| 16132 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16133 | MockWrite("GET / HTTP/1.1\r\n" |
| 16134 | "Host: www.example.org\r\n" |
| 16135 | "Connection: keep-alive\r\n\r\n"), |
| 16136 | MockWrite("GET /second HTTP/1.1\r\n" |
| 16137 | "Host: www.example.org\r\n" |
| 16138 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16139 | }; |
| 16140 | |
| 16141 | MockRead http_reads[] = { |
| 16142 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16143 | MockRead("Content-Type: text/html\r\n"), |
| 16144 | MockRead("Content-Length: 6\r\n\r\n"), |
| 16145 | MockRead("foobar"), |
| 16146 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16147 | MockRead("Content-Type: text/html\r\n"), |
| 16148 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16149 | MockRead("another"), |
| 16150 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16151 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16152 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16153 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16154 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16155 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16156 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16157 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16158 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16159 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16160 | http_server_properties->SetHttp2AlternativeService( |
| 16161 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16162 | |
| 16163 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 16164 | HttpRequestInfo request1; |
| 16165 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16166 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16167 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16168 | request1.traffic_annotation = |
| 16169 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16170 | TestCompletionCallback callback1; |
| 16171 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16172 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16173 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16174 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16175 | |
| 16176 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16177 | ASSERT_TRUE(response1); |
| 16178 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16179 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 16180 | |
| 16181 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16182 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16183 | EXPECT_EQ("foobar", response_data1); |
| 16184 | |
| 16185 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 16186 | // for alternative service. |
| 16187 | EXPECT_TRUE( |
| 16188 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 16189 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16190 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16191 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16192 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16193 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 16194 | HttpRequestInfo request2; |
| 16195 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16196 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16197 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16198 | request2.traffic_annotation = |
| 16199 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16200 | TestCompletionCallback callback2; |
| 16201 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16202 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16203 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16204 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16205 | |
| 16206 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16207 | ASSERT_TRUE(response2); |
| 16208 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16209 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 16210 | |
| 16211 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16212 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16213 | EXPECT_EQ("another", response_data2); |
| 16214 | } |
| 16215 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16216 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 16217 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 16218 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16219 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16220 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16221 | HostPortPair alternative("alternative.example.org", 443); |
| 16222 | std::string origin_url = "https://origin.example.org:443"; |
| 16223 | std::string alternative_url = "https://alternative.example.org:443"; |
| 16224 | |
| 16225 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 16226 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16227 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16228 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16229 | |
| 16230 | // HTTP/1.1 data for |request1| and |request2|. |
| 16231 | MockWrite http_writes[] = { |
| 16232 | MockWrite( |
| 16233 | "GET / HTTP/1.1\r\n" |
| 16234 | "Host: alternative.example.org\r\n" |
| 16235 | "Connection: keep-alive\r\n\r\n"), |
| 16236 | MockWrite( |
| 16237 | "GET / HTTP/1.1\r\n" |
| 16238 | "Host: alternative.example.org\r\n" |
| 16239 | "Connection: keep-alive\r\n\r\n"), |
| 16240 | }; |
| 16241 | |
| 16242 | MockRead http_reads[] = { |
| 16243 | MockRead( |
| 16244 | "HTTP/1.1 200 OK\r\n" |
| 16245 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16246 | "Content-Length: 40\r\n\r\n" |
| 16247 | "first HTTP/1.1 response from alternative"), |
| 16248 | MockRead( |
| 16249 | "HTTP/1.1 200 OK\r\n" |
| 16250 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16251 | "Content-Length: 41\r\n\r\n" |
| 16252 | "second HTTP/1.1 response from alternative"), |
| 16253 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16254 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16255 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16256 | |
| 16257 | // This test documents that an alternate Job should not pool to an already |
| 16258 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16259 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16260 | StaticSocketDataProvider data_refused; |
| 16261 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 16262 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 16263 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16264 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16265 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16266 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16267 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16268 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16269 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16270 | http_server_properties->SetHttp2AlternativeService( |
| 16271 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16272 | |
| 16273 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16274 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16275 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16276 | request1.method = "GET"; |
| 16277 | request1.url = GURL(alternative_url); |
| 16278 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16279 | request1.traffic_annotation = |
| 16280 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16281 | TestCompletionCallback callback1; |
| 16282 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16283 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16284 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16285 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16286 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16287 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16288 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16289 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16290 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 16291 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16292 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16293 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 16294 | |
| 16295 | // Request for origin.example.org, which has an alternative service. This |
| 16296 | // will start two Jobs: the alternative looks for connections to pool to, |
| 16297 | // 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] | 16298 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16299 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16300 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16301 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16302 | request2.method = "GET"; |
| 16303 | request2.url = GURL(origin_url); |
| 16304 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16305 | request2.traffic_annotation = |
| 16306 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16307 | TestCompletionCallback callback2; |
| 16308 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16309 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16310 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16311 | |
| 16312 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 16313 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16314 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16315 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16316 | request3.method = "GET"; |
| 16317 | request3.url = GURL(alternative_url); |
| 16318 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16319 | request3.traffic_annotation = |
| 16320 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16321 | TestCompletionCallback callback3; |
| 16322 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16323 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16324 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16325 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16326 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16327 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16328 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16329 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16330 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 16331 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16332 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16333 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 16334 | } |
| 16335 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16336 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16337 | const std::string https_url = "https://www.example.org:8080/"; |
| 16338 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16339 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16340 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16341 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16342 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16343 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16344 | const HostPortPair host_port_pair("www.example.org", 8080); |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 16345 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
| 16346 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 16347 | host_port_pair)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16348 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16349 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16350 | spdy::SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 16351 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 16352 | |
| 16353 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16354 | spdy::SpdyHeaderBlock req2_block; |
| 16355 | req2_block[spdy::kHttp2MethodHeader] = "GET"; |
| 16356 | req2_block[spdy::kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 16357 | req2_block[spdy::kHttp2SchemeHeader] = "http"; |
| 16358 | req2_block[spdy::kHttp2PathHeader] = "/"; |
| 16359 | spdy::SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16360 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16361 | |
| 16362 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16363 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 16364 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16365 | }; |
| 16366 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16367 | spdy::SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16368 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16369 | spdy::SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16370 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16371 | spdy::SpdySerializedFrame body1( |
| 16372 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 16373 | spdy::SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16374 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16375 | spdy::SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16376 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16377 | spdy::SpdySerializedFrame resp2( |
| 16378 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16379 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16380 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16381 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16382 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16383 | CreateMockRead(wrapped_resp1, 4), |
| 16384 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16385 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16386 | CreateMockRead(resp2, 8), |
| 16387 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16388 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 16389 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16390 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16391 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16392 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 16393 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16394 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 16395 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16396 | ProxyResolutionService::CreateFixedFromPacResult( |
| 16397 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 16398 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16399 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16400 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16401 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16402 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16403 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16404 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16405 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16406 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16407 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16408 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16409 | |
| 16410 | // Start the first transaction to set up the SpdySession |
| 16411 | HttpRequestInfo request1; |
| 16412 | request1.method = "GET"; |
| 16413 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16414 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16415 | request1.traffic_annotation = |
| 16416 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16417 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16418 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16419 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16420 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16421 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16422 | data1.RunUntilPaused(); |
| 16423 | base::RunLoop().RunUntilIdle(); |
| 16424 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16425 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16426 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16427 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16428 | LoadTimingInfo load_timing_info1; |
| 16429 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 16430 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 16431 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 16432 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16433 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16434 | HttpRequestInfo request2; |
| 16435 | request2.method = "GET"; |
| 16436 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16437 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16438 | request2.traffic_annotation = |
| 16439 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16440 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16441 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16442 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16443 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16444 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16445 | data1.RunUntilPaused(); |
| 16446 | base::RunLoop().RunUntilIdle(); |
| 16447 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16448 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16449 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16450 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16451 | |
| 16452 | LoadTimingInfo load_timing_info2; |
| 16453 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 16454 | // The established SPDY sessions is considered reused by the HTTP request. |
| 16455 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 16456 | // HTTP requests over a SPDY session should have a different connection |
| 16457 | // socket_log_id than requests over a tunnel. |
| 16458 | 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] | 16459 | } |
| 16460 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16461 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 16462 | // that we do not pool other origins that resolve to the same IP when |
| 16463 | // the certificate does not match the new origin. |
| 16464 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16465 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16466 | const std::string url1 = "http://www.example.org/"; |
| 16467 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16468 | const std::string ip_addr = "1.2.3.4"; |
| 16469 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16470 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16471 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16472 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16473 | // SPDY GET for HTTP URL (through SPDY proxy) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16474 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16475 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16476 | spdy::SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16477 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16478 | |
| 16479 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16480 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16481 | }; |
| 16482 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16483 | spdy::SpdySerializedFrame resp1( |
| 16484 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16485 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16486 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16487 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 16488 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16489 | }; |
| 16490 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16491 | SequencedSocketData data1(reads1, writes1); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 16492 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 16493 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16494 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 16495 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16496 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16497 | |
| 16498 | // SPDY GET for HTTPS URL (direct) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16499 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16500 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16501 | |
| 16502 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16503 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16504 | }; |
| 16505 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16506 | spdy::SpdySerializedFrame resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16507 | spdy_util_secure.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16508 | spdy::SpdySerializedFrame body2( |
| 16509 | spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16510 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16511 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16512 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16513 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16514 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16515 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16516 | |
| 16517 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 16518 | // all others direct. |
| 16519 | ProxyConfig proxy_config; |
| 16520 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16521 | session_deps_.proxy_resolution_service = |
| 16522 | std::make_unique<ProxyResolutionService>( |
| 16523 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 16524 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 16525 | nullptr, nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16526 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16527 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16528 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16529 | // Load a valid cert. Note, that this does not need to |
| 16530 | // be valid for proxy because the MockSSLClientSocket does |
| 16531 | // not actually verify it. But SpdySession will use this |
| 16532 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 16533 | ssl1.ssl_info.cert = |
| 16534 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 16535 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16536 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16537 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16538 | |
| 16539 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16540 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16541 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16542 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16543 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16544 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16545 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16546 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16547 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16548 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16549 | |
| 16550 | // Start the first transaction to set up the SpdySession |
| 16551 | HttpRequestInfo request1; |
| 16552 | request1.method = "GET"; |
| 16553 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16554 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16555 | request1.traffic_annotation = |
| 16556 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16557 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16558 | TestCompletionCallback callback1; |
| 16559 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16560 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16561 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16562 | data1.RunUntilPaused(); |
| 16563 | base::RunLoop().RunUntilIdle(); |
| 16564 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16565 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16566 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16567 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16568 | |
| 16569 | // Now, start the HTTP request |
| 16570 | HttpRequestInfo request2; |
| 16571 | request2.method = "GET"; |
| 16572 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16573 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16574 | request2.traffic_annotation = |
| 16575 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16576 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16577 | TestCompletionCallback callback2; |
| 16578 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16579 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16580 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16581 | |
| 16582 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16583 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16584 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16585 | } |
| 16586 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16587 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 16588 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 16589 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 16590 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16591 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16592 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16593 | |
| 16594 | MockRead reads1[] = { |
| 16595 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 16596 | }; |
| 16597 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16598 | SequencedSocketData data1(reads1, base::span<MockWrite>()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16599 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16600 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16601 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16602 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16603 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16604 | }; |
| 16605 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16606 | spdy::SpdySerializedFrame resp2( |
| 16607 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16608 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16609 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16610 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 16611 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16612 | }; |
| 16613 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16614 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16615 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16616 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16617 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16618 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16619 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16620 | |
| 16621 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16622 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16623 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16624 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16625 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16626 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16627 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16628 | |
| 16629 | // Start the first transaction to set up the SpdySession and verify that |
| 16630 | // connection was closed. |
| 16631 | HttpRequestInfo request1; |
| 16632 | request1.method = "GET"; |
| 16633 | request1.url = GURL(https_url); |
| 16634 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16635 | request1.traffic_annotation = |
| 16636 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16637 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16638 | TestCompletionCallback callback1; |
| 16639 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16640 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16641 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16642 | |
| 16643 | // Now, start the second request and make sure it succeeds. |
| 16644 | HttpRequestInfo request2; |
| 16645 | request2.method = "GET"; |
| 16646 | request2.url = GURL(https_url); |
| 16647 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16648 | request2.traffic_annotation = |
| 16649 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16650 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16651 | TestCompletionCallback callback2; |
| 16652 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16653 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16654 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16655 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16656 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16657 | } |
| 16658 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16659 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16660 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16661 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16662 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16663 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16664 | |
| 16665 | // Use two different hosts with different IPs so they don't get pooled. |
| 16666 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 16667 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16668 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16669 | |
| 16670 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16671 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16672 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16673 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16674 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16675 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16676 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16677 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16678 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16679 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16680 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16681 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16682 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16683 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16684 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16685 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16686 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16687 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16688 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16689 | }; |
| 16690 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16691 | // Use a separate test instance for the separate SpdySession that will be |
| 16692 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16693 | SpdyTestUtil spdy_util_2; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16694 | SequencedSocketData spdy1_data(spdy1_reads, spdy1_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 16695 | session_deps_.socket_factory->AddSocketDataProvider(&spdy1_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16696 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16697 | spdy::SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16698 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16699 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16700 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16701 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16702 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16703 | spdy_util_2.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16704 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16705 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16706 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16707 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16708 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16709 | }; |
| 16710 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16711 | SequencedSocketData spdy2_data(spdy2_reads, spdy2_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 16712 | session_deps_.socket_factory->AddSocketDataProvider(&spdy2_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16713 | |
| 16714 | MockWrite http_write[] = { |
| 16715 | MockWrite("GET / HTTP/1.1\r\n" |
| 16716 | "Host: www.a.com\r\n" |
| 16717 | "Connection: keep-alive\r\n\r\n"), |
| 16718 | }; |
| 16719 | |
| 16720 | MockRead http_read[] = { |
| 16721 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16722 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 16723 | MockRead("Content-Length: 6\r\n\r\n"), |
| 16724 | MockRead("hello!"), |
| 16725 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16726 | StaticSocketDataProvider http_data(http_read, http_write); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16727 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16728 | |
| 16729 | HostPortPair host_port_pair_a("www.a.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16730 | SpdySessionKey spdy_session_key_a( |
| 16731 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16732 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16733 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16734 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16735 | |
| 16736 | TestCompletionCallback callback; |
| 16737 | HttpRequestInfo request1; |
| 16738 | request1.method = "GET"; |
| 16739 | request1.url = GURL("https://www.a.com/"); |
| 16740 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16741 | request1.traffic_annotation = |
| 16742 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16743 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16744 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16745 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16746 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16747 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16748 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16749 | |
| 16750 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16751 | ASSERT_TRUE(response); |
| 16752 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16753 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16754 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16755 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16756 | |
| 16757 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16758 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16759 | EXPECT_EQ("hello!", response_data); |
| 16760 | trans.reset(); |
| 16761 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16762 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16763 | |
| 16764 | HostPortPair host_port_pair_b("www.b.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16765 | SpdySessionKey spdy_session_key_b( |
| 16766 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16767 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16768 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16769 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16770 | HttpRequestInfo request2; |
| 16771 | request2.method = "GET"; |
| 16772 | request2.url = GURL("https://www.b.com/"); |
| 16773 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16774 | request2.traffic_annotation = |
| 16775 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16776 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16777 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16778 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16779 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16780 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16781 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16782 | |
| 16783 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16784 | ASSERT_TRUE(response); |
| 16785 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16786 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16787 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16788 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16789 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16790 | EXPECT_EQ("hello!", response_data); |
| 16791 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16792 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16793 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16794 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16795 | |
| 16796 | HostPortPair host_port_pair_a1("www.a.com", 80); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16797 | SpdySessionKey spdy_session_key_a1( |
| 16798 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16799 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16800 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16801 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16802 | HttpRequestInfo request3; |
| 16803 | request3.method = "GET"; |
| 16804 | request3.url = GURL("http://www.a.com/"); |
| 16805 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16806 | request3.traffic_annotation = |
| 16807 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16808 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16809 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16810 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16811 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16812 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16813 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16814 | |
| 16815 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16816 | ASSERT_TRUE(response); |
| 16817 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16818 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 16819 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16820 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16821 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16822 | EXPECT_EQ("hello!", response_data); |
| 16823 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16824 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16825 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16826 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16827 | } |
| 16828 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16829 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16830 | HttpRequestInfo request; |
| 16831 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16832 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16833 | request.traffic_annotation = |
| 16834 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16835 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16836 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16837 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16838 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16839 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16840 | StaticSocketDataProvider data; |
| 16841 | data.set_connect_data(mock_connect); |
| 16842 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16843 | |
| 16844 | TestCompletionCallback callback; |
| 16845 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16846 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16847 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16848 | |
| 16849 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16850 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16851 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16852 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16853 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16854 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16855 | |
| 16856 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16857 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16858 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16859 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16860 | |
| 16861 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16862 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16863 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16864 | } |
| 16865 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16866 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[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 | b5e433e | 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 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16876 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16877 | StaticSocketDataProvider data; |
| 16878 | data.set_connect_data(mock_connect); |
| 16879 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16880 | |
| 16881 | TestCompletionCallback callback; |
| 16882 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16883 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16884 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16885 | |
| 16886 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16887 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16888 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16889 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16890 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16891 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16892 | |
| 16893 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16894 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16895 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16896 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16897 | |
| 16898 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16899 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16900 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16901 | } |
| 16902 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16903 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16904 | HttpRequestInfo request; |
| 16905 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16906 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16907 | request.traffic_annotation = |
| 16908 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16909 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16910 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16911 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16912 | |
| 16913 | MockWrite data_writes[] = { |
| 16914 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16915 | }; |
| 16916 | MockRead data_reads[] = { |
| 16917 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16918 | }; |
| 16919 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16920 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16921 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16922 | |
| 16923 | TestCompletionCallback callback; |
| 16924 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16925 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16926 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16927 | |
| 16928 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16929 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16930 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16931 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16932 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16933 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16934 | } |
| 16935 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16936 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16937 | HttpRequestInfo request; |
| 16938 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16939 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16940 | request.traffic_annotation = |
| 16941 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16942 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16943 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16944 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16945 | |
| 16946 | MockWrite data_writes[] = { |
| 16947 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 16948 | }; |
| 16949 | MockRead data_reads[] = { |
| 16950 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16951 | }; |
| 16952 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16953 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16954 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16955 | |
| 16956 | TestCompletionCallback callback; |
| 16957 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16958 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16959 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16960 | |
| 16961 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16962 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16963 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16964 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16965 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16966 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16967 | } |
| 16968 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16969 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16970 | HttpRequestInfo request; |
| 16971 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16972 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16973 | request.traffic_annotation = |
| 16974 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16975 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16976 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16977 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16978 | |
| 16979 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16980 | MockWrite( |
| 16981 | "GET / HTTP/1.1\r\n" |
| 16982 | "Host: www.example.org\r\n" |
| 16983 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16984 | }; |
| 16985 | MockRead data_reads[] = { |
| 16986 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16987 | }; |
| 16988 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16989 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16990 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16991 | |
| 16992 | TestCompletionCallback callback; |
| 16993 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16994 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16995 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16996 | |
| 16997 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16998 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16999 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17000 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17001 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17002 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 17003 | } |
| 17004 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17005 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17006 | HttpRequestInfo request; |
| 17007 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17008 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17009 | request.traffic_annotation = |
| 17010 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17011 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17012 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17013 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17014 | |
| 17015 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17016 | MockWrite( |
| 17017 | "GET / HTTP/1.1\r\n" |
| 17018 | "Host: www.example.org\r\n" |
| 17019 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17020 | }; |
| 17021 | MockRead data_reads[] = { |
| 17022 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 17023 | }; |
| 17024 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17025 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17026 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17027 | |
| 17028 | TestCompletionCallback callback; |
| 17029 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17030 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17031 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17032 | |
| 17033 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17034 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17035 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17036 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17037 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17038 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 17039 | } |
| 17040 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17041 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17042 | HttpRequestInfo request; |
| 17043 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17044 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17045 | request.extra_headers.SetHeader("X-Foo", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17046 | request.traffic_annotation = |
| 17047 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17048 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17049 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17050 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17051 | |
| 17052 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17053 | MockWrite( |
| 17054 | "GET / HTTP/1.1\r\n" |
| 17055 | "Host: www.example.org\r\n" |
| 17056 | "Connection: keep-alive\r\n" |
| 17057 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17058 | }; |
| 17059 | MockRead data_reads[] = { |
| 17060 | MockRead("HTTP/1.1 200 OK\r\n" |
| 17061 | "Content-Length: 5\r\n\r\n" |
| 17062 | "hello"), |
| 17063 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 17064 | }; |
| 17065 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17066 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17067 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17068 | |
| 17069 | TestCompletionCallback callback; |
| 17070 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17071 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17072 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17073 | |
| 17074 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17075 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17076 | |
| 17077 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17078 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17079 | std::string foo; |
| 17080 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 17081 | EXPECT_EQ("bar", foo); |
| 17082 | } |
| 17083 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17084 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 17085 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17086 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17087 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17088 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17089 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17090 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17091 | |
| 17092 | // Set up SSL request. |
| 17093 | |
| 17094 | HttpRequestInfo ssl_request; |
| 17095 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17096 | ssl_request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17097 | ssl_request.traffic_annotation = |
| 17098 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17099 | |
| 17100 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17101 | MockWrite( |
| 17102 | "GET / HTTP/1.1\r\n" |
| 17103 | "Host: www.example.org\r\n" |
| 17104 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17105 | }; |
| 17106 | MockRead ssl_reads[] = { |
| 17107 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17108 | MockRead("Content-Length: 11\r\n\r\n"), |
| 17109 | MockRead("hello world"), |
| 17110 | MockRead(SYNCHRONOUS, OK), |
| 17111 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17112 | StaticSocketDataProvider ssl_data(ssl_reads, ssl_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17113 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 17114 | |
| 17115 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17116 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17117 | |
| 17118 | // Set up HTTP request. |
| 17119 | |
| 17120 | HttpRequestInfo http_request; |
| 17121 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17122 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17123 | http_request.traffic_annotation = |
| 17124 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17125 | |
| 17126 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17127 | MockWrite( |
| 17128 | "GET / HTTP/1.1\r\n" |
| 17129 | "Host: www.example.org\r\n" |
| 17130 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17131 | }; |
| 17132 | MockRead http_reads[] = { |
| 17133 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17134 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17135 | MockRead("falafel"), |
| 17136 | MockRead(SYNCHRONOUS, OK), |
| 17137 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17138 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17139 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17140 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17141 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17142 | |
| 17143 | // Start the SSL request. |
| 17144 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17145 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17146 | ASSERT_EQ(ERR_IO_PENDING, |
| 17147 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 17148 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17149 | |
| 17150 | // Start the HTTP request. Pool should stall. |
| 17151 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17152 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17153 | ASSERT_EQ(ERR_IO_PENDING, |
| 17154 | http_trans.Start(&http_request, http_callback.callback(), |
| 17155 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17156 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17157 | |
| 17158 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17159 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17160 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17161 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17162 | EXPECT_EQ("hello world", response_data); |
| 17163 | |
| 17164 | // The SSL socket should automatically be closed, so the HTTP request can |
| 17165 | // start. |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 17166 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17167 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17168 | |
| 17169 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17170 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17171 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17172 | EXPECT_EQ("falafel", response_data); |
| 17173 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17174 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17175 | } |
| 17176 | |
| 17177 | // Tests that when a SSL connection is established but there's no corresponding |
| 17178 | // request that needs it, the new socket is closed if the transport socket pool |
| 17179 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17180 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17181 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17182 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17183 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17184 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17185 | |
| 17186 | // Set up an ssl request. |
| 17187 | |
| 17188 | HttpRequestInfo ssl_request; |
| 17189 | ssl_request.method = "GET"; |
| 17190 | ssl_request.url = GURL("https://www.foopy.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17191 | ssl_request.traffic_annotation = |
| 17192 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17193 | |
| 17194 | // No data will be sent on the SSL socket. |
| 17195 | StaticSocketDataProvider ssl_data; |
| 17196 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 17197 | |
| 17198 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17199 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17200 | |
| 17201 | // Set up HTTP request. |
| 17202 | |
| 17203 | HttpRequestInfo http_request; |
| 17204 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17205 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17206 | http_request.traffic_annotation = |
| 17207 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17208 | |
| 17209 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17210 | MockWrite( |
| 17211 | "GET / HTTP/1.1\r\n" |
| 17212 | "Host: www.example.org\r\n" |
| 17213 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17214 | }; |
| 17215 | MockRead http_reads[] = { |
| 17216 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17217 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17218 | MockRead("falafel"), |
| 17219 | MockRead(SYNCHRONOUS, OK), |
| 17220 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17221 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17222 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17223 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17224 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17225 | |
| 17226 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 17227 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 17228 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 17229 | http_stream_factory->PreconnectStreams(1, ssl_request); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 17230 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17231 | |
| 17232 | // Start the HTTP request. Pool should stall. |
| 17233 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17234 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17235 | ASSERT_EQ(ERR_IO_PENDING, |
| 17236 | http_trans.Start(&http_request, http_callback.callback(), |
| 17237 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17238 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17239 | |
| 17240 | // The SSL connection will automatically be closed once the connection is |
| 17241 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17242 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17243 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17244 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17245 | EXPECT_EQ("falafel", response_data); |
| 17246 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17247 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17248 | } |
| 17249 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17250 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17251 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17252 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17253 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17254 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17255 | |
| 17256 | HttpRequestInfo request; |
| 17257 | request.method = "POST"; |
| 17258 | request.url = GURL("http://www.foo.com/"); |
| 17259 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17260 | request.traffic_annotation = |
| 17261 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17262 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17263 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17264 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17265 | // Send headers successfully, but get an error while sending the body. |
| 17266 | MockWrite data_writes[] = { |
| 17267 | MockWrite("POST / HTTP/1.1\r\n" |
| 17268 | "Host: www.foo.com\r\n" |
| 17269 | "Connection: keep-alive\r\n" |
| 17270 | "Content-Length: 3\r\n\r\n"), |
| 17271 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17272 | }; |
| 17273 | |
| 17274 | MockRead data_reads[] = { |
| 17275 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17276 | MockRead("hello world"), |
| 17277 | MockRead(SYNCHRONOUS, OK), |
| 17278 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17279 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17280 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17281 | |
| 17282 | TestCompletionCallback callback; |
| 17283 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17284 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17285 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17286 | |
| 17287 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17288 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17289 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17290 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17291 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17292 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17293 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17294 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17295 | |
| 17296 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17297 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17298 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17299 | EXPECT_EQ("hello world", response_data); |
| 17300 | } |
| 17301 | |
| 17302 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 17303 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17304 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17305 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17306 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17307 | MockWrite data_writes[] = { |
| 17308 | MockWrite("GET / HTTP/1.1\r\n" |
| 17309 | "Host: www.foo.com\r\n" |
| 17310 | "Connection: keep-alive\r\n\r\n"), |
| 17311 | MockWrite("POST / HTTP/1.1\r\n" |
| 17312 | "Host: www.foo.com\r\n" |
| 17313 | "Connection: keep-alive\r\n" |
| 17314 | "Content-Length: 3\r\n\r\n"), |
| 17315 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17316 | }; |
| 17317 | |
| 17318 | MockRead data_reads[] = { |
| 17319 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 17320 | "Content-Length: 14\r\n\r\n"), |
| 17321 | MockRead("first response"), |
| 17322 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 17323 | "Content-Length: 15\r\n\r\n"), |
| 17324 | MockRead("second response"), |
| 17325 | MockRead(SYNCHRONOUS, OK), |
| 17326 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17327 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17328 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17329 | |
| 17330 | TestCompletionCallback callback; |
| 17331 | HttpRequestInfo request1; |
| 17332 | request1.method = "GET"; |
| 17333 | request1.url = GURL("http://www.foo.com/"); |
| 17334 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17335 | request1.traffic_annotation = |
| 17336 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17337 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17338 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17339 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17340 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17341 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17342 | |
| 17343 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17344 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17345 | |
| 17346 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17347 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17348 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17349 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17350 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 17351 | |
| 17352 | std::string response_data1; |
| 17353 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17354 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17355 | EXPECT_EQ("first response", response_data1); |
| 17356 | // Delete the transaction to release the socket back into the socket pool. |
| 17357 | trans1.reset(); |
| 17358 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17359 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17360 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17361 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17362 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17363 | |
| 17364 | HttpRequestInfo request2; |
| 17365 | request2.method = "POST"; |
| 17366 | request2.url = GURL("http://www.foo.com/"); |
| 17367 | request2.upload_data_stream = &upload_data_stream; |
| 17368 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17369 | request2.traffic_annotation = |
| 17370 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17371 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17372 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17373 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17374 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17375 | |
| 17376 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17377 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17378 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17379 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17380 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17381 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17382 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17383 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 17384 | |
| 17385 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17386 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17387 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17388 | EXPECT_EQ("second response", response_data2); |
| 17389 | } |
| 17390 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17391 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17392 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17393 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17394 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17395 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17396 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17397 | |
| 17398 | HttpRequestInfo request; |
| 17399 | request.method = "POST"; |
| 17400 | request.url = GURL("http://www.foo.com/"); |
| 17401 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17402 | request.traffic_annotation = |
| 17403 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17404 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17405 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17406 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17407 | // Send headers successfully, but get an error while sending the body. |
| 17408 | MockWrite data_writes[] = { |
| 17409 | MockWrite("POST / HTTP/1.1\r\n" |
| 17410 | "Host: www.foo.com\r\n" |
| 17411 | "Connection: keep-alive\r\n" |
| 17412 | "Content-Length: 3\r\n\r\n" |
| 17413 | "fo"), |
| 17414 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17415 | }; |
| 17416 | |
| 17417 | MockRead data_reads[] = { |
| 17418 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17419 | MockRead("hello world"), |
| 17420 | MockRead(SYNCHRONOUS, OK), |
| 17421 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17422 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17423 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17424 | |
| 17425 | TestCompletionCallback callback; |
| 17426 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17427 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17428 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17429 | |
| 17430 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17431 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17432 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17433 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17434 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17435 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17436 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17437 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17438 | |
| 17439 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17440 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17441 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17442 | EXPECT_EQ("hello world", response_data); |
| 17443 | } |
| 17444 | |
| 17445 | // This tests the more common case than the previous test, where headers and |
| 17446 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17447 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17448 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17449 | |
| 17450 | HttpRequestInfo request; |
| 17451 | request.method = "POST"; |
| 17452 | request.url = GURL("http://www.foo.com/"); |
| 17453 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17454 | request.traffic_annotation = |
| 17455 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17456 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17457 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17458 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17459 | // Send headers successfully, but get an error while sending the body. |
| 17460 | MockWrite data_writes[] = { |
| 17461 | MockWrite("POST / HTTP/1.1\r\n" |
| 17462 | "Host: www.foo.com\r\n" |
| 17463 | "Connection: keep-alive\r\n" |
| 17464 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17465 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17466 | }; |
| 17467 | |
| 17468 | MockRead data_reads[] = { |
| 17469 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17470 | MockRead("hello world"), |
| 17471 | MockRead(SYNCHRONOUS, OK), |
| 17472 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17473 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17474 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17475 | |
| 17476 | TestCompletionCallback callback; |
| 17477 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17478 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17479 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17480 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 17481 | // they can't be merged with the body in a single send. Not currently |
| 17482 | // necessary since a chunked body is never merged with headers, but this makes |
| 17483 | // the test more future proof. |
| 17484 | base::RunLoop().RunUntilIdle(); |
| 17485 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17486 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17487 | |
| 17488 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17489 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17490 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17491 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17492 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17493 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17494 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17495 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17496 | |
| 17497 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17498 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17499 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17500 | EXPECT_EQ("hello world", response_data); |
| 17501 | } |
| 17502 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17503 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17504 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17505 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17506 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17507 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17508 | |
| 17509 | HttpRequestInfo request; |
| 17510 | request.method = "POST"; |
| 17511 | request.url = GURL("http://www.foo.com/"); |
| 17512 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17513 | request.traffic_annotation = |
| 17514 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17515 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17516 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17517 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17518 | |
| 17519 | MockWrite data_writes[] = { |
| 17520 | MockWrite("POST / HTTP/1.1\r\n" |
| 17521 | "Host: www.foo.com\r\n" |
| 17522 | "Connection: keep-alive\r\n" |
| 17523 | "Content-Length: 3\r\n\r\n"), |
| 17524 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17525 | }; |
| 17526 | |
| 17527 | MockRead data_reads[] = { |
| 17528 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17529 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17530 | MockRead("hello world"), |
| 17531 | MockRead(SYNCHRONOUS, OK), |
| 17532 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17533 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17534 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17535 | |
| 17536 | TestCompletionCallback callback; |
| 17537 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17538 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17539 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17540 | |
| 17541 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17542 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17543 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17544 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17545 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17546 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17547 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17548 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17549 | |
| 17550 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17551 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17552 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17553 | EXPECT_EQ("hello world", response_data); |
| 17554 | } |
| 17555 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17556 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17557 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17558 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17559 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17560 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17561 | |
| 17562 | HttpRequestInfo request; |
| 17563 | request.method = "POST"; |
| 17564 | request.url = GURL("http://www.foo.com/"); |
| 17565 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17566 | request.traffic_annotation = |
| 17567 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17568 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17569 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17570 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17571 | // Send headers successfully, but get an error while sending the body. |
| 17572 | MockWrite data_writes[] = { |
| 17573 | MockWrite("POST / HTTP/1.1\r\n" |
| 17574 | "Host: www.foo.com\r\n" |
| 17575 | "Connection: keep-alive\r\n" |
| 17576 | "Content-Length: 3\r\n\r\n"), |
| 17577 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17578 | }; |
| 17579 | |
| 17580 | MockRead data_reads[] = { |
| 17581 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 17582 | MockRead("hello world"), |
| 17583 | MockRead(SYNCHRONOUS, OK), |
| 17584 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17585 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17586 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17587 | |
| 17588 | TestCompletionCallback callback; |
| 17589 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17590 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17591 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17592 | |
| 17593 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17594 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17595 | } |
| 17596 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17597 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17598 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17599 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17600 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17601 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17602 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17603 | |
| 17604 | HttpRequestInfo request; |
| 17605 | request.method = "POST"; |
| 17606 | request.url = GURL("http://www.foo.com/"); |
| 17607 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17608 | request.traffic_annotation = |
| 17609 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17610 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17611 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17612 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17613 | // Send headers successfully, but get an error while sending the body. |
| 17614 | MockWrite data_writes[] = { |
| 17615 | MockWrite("POST / HTTP/1.1\r\n" |
| 17616 | "Host: www.foo.com\r\n" |
| 17617 | "Connection: keep-alive\r\n" |
| 17618 | "Content-Length: 3\r\n\r\n"), |
| 17619 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17620 | }; |
| 17621 | |
| 17622 | MockRead data_reads[] = { |
| 17623 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17624 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 17625 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 17626 | MockRead("Content-Length: 0\r\n\r\n"), |
| 17627 | MockRead(SYNCHRONOUS, OK), |
| 17628 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17629 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17630 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17631 | |
| 17632 | TestCompletionCallback callback; |
| 17633 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17634 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17635 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17636 | |
| 17637 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17638 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17639 | } |
| 17640 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17641 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17642 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17643 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17644 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17645 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17646 | |
| 17647 | HttpRequestInfo request; |
| 17648 | request.method = "POST"; |
| 17649 | request.url = GURL("http://www.foo.com/"); |
| 17650 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17651 | request.traffic_annotation = |
| 17652 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17653 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17654 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17655 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17656 | // Send headers successfully, but get an error while sending the body. |
| 17657 | MockWrite data_writes[] = { |
| 17658 | MockWrite("POST / HTTP/1.1\r\n" |
| 17659 | "Host: www.foo.com\r\n" |
| 17660 | "Connection: keep-alive\r\n" |
| 17661 | "Content-Length: 3\r\n\r\n"), |
| 17662 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17663 | }; |
| 17664 | |
| 17665 | MockRead data_reads[] = { |
| 17666 | MockRead("HTTP 0.9 rocks!"), |
| 17667 | MockRead(SYNCHRONOUS, OK), |
| 17668 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17669 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17670 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17671 | |
| 17672 | TestCompletionCallback callback; |
| 17673 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17674 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17675 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17676 | |
| 17677 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17678 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17679 | } |
| 17680 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17681 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17682 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17683 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17684 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17685 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17686 | |
| 17687 | HttpRequestInfo request; |
| 17688 | request.method = "POST"; |
| 17689 | request.url = GURL("http://www.foo.com/"); |
| 17690 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17691 | request.traffic_annotation = |
| 17692 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17693 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17694 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17695 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17696 | // Send headers successfully, but get an error while sending the body. |
| 17697 | MockWrite data_writes[] = { |
| 17698 | MockWrite("POST / HTTP/1.1\r\n" |
| 17699 | "Host: www.foo.com\r\n" |
| 17700 | "Connection: keep-alive\r\n" |
| 17701 | "Content-Length: 3\r\n\r\n"), |
| 17702 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17703 | }; |
| 17704 | |
| 17705 | MockRead data_reads[] = { |
| 17706 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 17707 | MockRead(SYNCHRONOUS, OK), |
| 17708 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17709 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17710 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17711 | |
| 17712 | TestCompletionCallback callback; |
| 17713 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17714 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17715 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17716 | |
| 17717 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17718 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17719 | } |
| 17720 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17721 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17722 | |
| 17723 | namespace { |
| 17724 | |
| 17725 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
| 17726 | headers->SetHeader("Connection", "Upgrade"); |
| 17727 | headers->SetHeader("Upgrade", "websocket"); |
| 17728 | headers->SetHeader("Origin", "http://www.example.org"); |
| 17729 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17730 | } |
| 17731 | |
| 17732 | } // namespace |
| 17733 | |
| 17734 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17735 | for (bool secure : {true, false}) { |
| 17736 | MockWrite data_writes[] = { |
| 17737 | MockWrite("GET / HTTP/1.1\r\n" |
| 17738 | "Host: www.example.org\r\n" |
| 17739 | "Connection: Upgrade\r\n" |
| 17740 | "Upgrade: websocket\r\n" |
| 17741 | "Origin: http://www.example.org\r\n" |
| 17742 | "Sec-WebSocket-Version: 13\r\n" |
| 17743 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17744 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17745 | "client_max_window_bits\r\n\r\n")}; |
| 17746 | |
| 17747 | MockRead data_reads[] = { |
| 17748 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17749 | "Upgrade: websocket\r\n" |
| 17750 | "Connection: Upgrade\r\n" |
| 17751 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
| 17752 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17753 | StaticSocketDataProvider data(data_reads, data_writes); |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17754 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17755 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17756 | if (secure) |
| 17757 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17758 | |
| 17759 | HttpRequestInfo request; |
| 17760 | request.method = "GET"; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17761 | request.url = |
| 17762 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 17763 | AddWebSocketHeaders(&request.extra_headers); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17764 | request.traffic_annotation = |
| 17765 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17766 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17767 | TestWebSocketHandshakeStreamCreateHelper |
| 17768 | websocket_handshake_stream_create_helper; |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17769 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17770 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17771 | HttpNetworkTransaction trans(LOW, session.get()); |
| 17772 | trans.SetWebSocketHandshakeStreamCreateHelper( |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17773 | &websocket_handshake_stream_create_helper); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17774 | |
| 17775 | TestCompletionCallback callback; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17776 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17777 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17778 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17779 | const HttpStreamRequest* stream_request = trans.stream_request_.get(); |
| 17780 | ASSERT_TRUE(stream_request); |
| 17781 | EXPECT_EQ(&websocket_handshake_stream_create_helper, |
| 17782 | stream_request->websocket_handshake_stream_create_helper()); |
| 17783 | |
| 17784 | rv = callback.WaitForResult(); |
| 17785 | EXPECT_THAT(rv, IsOk()); |
| 17786 | |
| 17787 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 17788 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17789 | } |
| 17790 | } |
| 17791 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17792 | // Verify that proxy headers are not sent to the destination server when |
| 17793 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17794 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17795 | HttpRequestInfo request; |
| 17796 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17797 | request.url = GURL("wss://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17798 | request.traffic_annotation = |
| 17799 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17800 | AddWebSocketHeaders(&request.extra_headers); |
| 17801 | |
| 17802 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17803 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17804 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17805 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17806 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17807 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17808 | |
| 17809 | // Since a proxy is configured, try to establish a tunnel. |
| 17810 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17811 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17812 | "Host: www.example.org:443\r\n" |
| 17813 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17814 | |
| 17815 | // After calling trans->RestartWithAuth(), this is the request we should |
| 17816 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17817 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17818 | "Host: www.example.org:443\r\n" |
| 17819 | "Proxy-Connection: keep-alive\r\n" |
| 17820 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17821 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17822 | MockWrite("GET / HTTP/1.1\r\n" |
| 17823 | "Host: www.example.org\r\n" |
| 17824 | "Connection: Upgrade\r\n" |
| 17825 | "Upgrade: websocket\r\n" |
| 17826 | "Origin: http://www.example.org\r\n" |
| 17827 | "Sec-WebSocket-Version: 13\r\n" |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17828 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17829 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17830 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17831 | |
| 17832 | // The proxy responds to the connect with a 407, using a persistent |
| 17833 | // connection. |
| 17834 | MockRead data_reads[] = { |
| 17835 | // No credentials. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17836 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 17837 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 17838 | "Content-Length: 0\r\n" |
| 17839 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17840 | |
| 17841 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17842 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17843 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17844 | "Upgrade: websocket\r\n" |
| 17845 | "Connection: Upgrade\r\n" |
| 17846 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17847 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17848 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17849 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17850 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17851 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17852 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17853 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17854 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17855 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17856 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17857 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17858 | &websocket_stream_create_helper); |
| 17859 | |
| 17860 | { |
| 17861 | TestCompletionCallback callback; |
| 17862 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17863 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17864 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17865 | |
| 17866 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17867 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17868 | } |
| 17869 | |
| 17870 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17871 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17872 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17873 | EXPECT_EQ(407, response->headers->response_code()); |
| 17874 | |
| 17875 | { |
| 17876 | TestCompletionCallback callback; |
| 17877 | |
| 17878 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 17879 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17880 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17881 | |
| 17882 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17883 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17884 | } |
| 17885 | |
| 17886 | response = trans->GetResponseInfo(); |
| 17887 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17888 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17889 | |
| 17890 | EXPECT_EQ(101, response->headers->response_code()); |
| 17891 | |
| 17892 | trans.reset(); |
| 17893 | session->CloseAllConnections(); |
| 17894 | } |
| 17895 | |
| 17896 | // Verify that proxy headers are not sent to the destination server when |
| 17897 | // establishing a tunnel for an insecure WebSocket connection. |
| 17898 | // This requires the authentication info to be injected into the auth cache |
| 17899 | // due to crbug.com/395064 |
| 17900 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17901 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17902 | HttpRequestInfo request; |
| 17903 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17904 | request.url = GURL("ws://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17905 | request.traffic_annotation = |
| 17906 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17907 | AddWebSocketHeaders(&request.extra_headers); |
| 17908 | |
| 17909 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17910 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17911 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17912 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17913 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17914 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17915 | |
| 17916 | MockWrite data_writes[] = { |
| 17917 | // Try to establish a tunnel for the WebSocket connection, with |
| 17918 | // credentials. Because WebSockets have a separate set of socket pools, |
| 17919 | // they cannot and will not use the same TCP/IP connection as the |
| 17920 | // preflight HTTP request. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17921 | MockWrite("CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 17922 | "Host: www.example.org:80\r\n" |
| 17923 | "Proxy-Connection: keep-alive\r\n" |
| 17924 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17925 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17926 | MockWrite("GET / HTTP/1.1\r\n" |
| 17927 | "Host: www.example.org\r\n" |
| 17928 | "Connection: Upgrade\r\n" |
| 17929 | "Upgrade: websocket\r\n" |
| 17930 | "Origin: http://www.example.org\r\n" |
| 17931 | "Sec-WebSocket-Version: 13\r\n" |
| 17932 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17933 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17934 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17935 | |
| 17936 | MockRead data_reads[] = { |
| 17937 | // HTTP CONNECT with credentials. |
| 17938 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17939 | |
| 17940 | // WebSocket connection established inside tunnel. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17941 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17942 | "Upgrade: websocket\r\n" |
| 17943 | "Connection: Upgrade\r\n" |
| 17944 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17945 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17946 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17947 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17948 | |
| 17949 | session->http_auth_cache()->Add( |
| 17950 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 17951 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 17952 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17953 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17954 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17955 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17956 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17957 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17958 | &websocket_stream_create_helper); |
| 17959 | |
| 17960 | TestCompletionCallback callback; |
| 17961 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17962 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17963 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17964 | |
| 17965 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17966 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17967 | |
| 17968 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17969 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17970 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17971 | |
| 17972 | EXPECT_EQ(101, response->headers->response_code()); |
| 17973 | |
| 17974 | trans.reset(); |
| 17975 | session->CloseAllConnections(); |
| 17976 | } |
| 17977 | |
Matt Menke | 1d6093e3 | 2019-03-22 17:33:43 | [diff] [blame] | 17978 | // WebSockets over QUIC is not supported, including over QUIC proxies. |
| 17979 | TEST_F(HttpNetworkTransactionTest, WebSocketNotSentOverQuicProxy) { |
| 17980 | for (bool secure : {true, false}) { |
| 17981 | SCOPED_TRACE(secure); |
| 17982 | session_deps_.proxy_resolution_service = |
| 17983 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17984 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 17985 | session_deps_.enable_quic = true; |
| 17986 | |
| 17987 | HttpRequestInfo request; |
| 17988 | request.url = |
| 17989 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 17990 | AddWebSocketHeaders(&request.extra_headers); |
| 17991 | request.traffic_annotation = |
| 17992 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 17993 | |
| 17994 | TestWebSocketHandshakeStreamCreateHelper |
| 17995 | websocket_handshake_stream_create_helper; |
| 17996 | |
| 17997 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17998 | HttpNetworkTransaction trans(LOW, session.get()); |
| 17999 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 18000 | &websocket_handshake_stream_create_helper); |
| 18001 | |
| 18002 | TestCompletionCallback callback; |
| 18003 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18004 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18005 | |
| 18006 | rv = callback.WaitForResult(); |
| 18007 | EXPECT_THAT(rv, IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 18008 | } |
| 18009 | } |
| 18010 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18011 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 18012 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18013 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18014 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18015 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18016 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18017 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18018 | |
| 18019 | HttpRequestInfo request; |
| 18020 | request.method = "POST"; |
| 18021 | request.url = GURL("http://www.foo.com/"); |
| 18022 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18023 | request.traffic_annotation = |
| 18024 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18025 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18026 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18027 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18028 | MockWrite data_writes[] = { |
| 18029 | MockWrite("POST / HTTP/1.1\r\n" |
| 18030 | "Host: www.foo.com\r\n" |
| 18031 | "Connection: keep-alive\r\n" |
| 18032 | "Content-Length: 3\r\n\r\n"), |
| 18033 | MockWrite("foo"), |
| 18034 | }; |
| 18035 | |
| 18036 | MockRead data_reads[] = { |
| 18037 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18038 | MockRead(SYNCHRONOUS, OK), |
| 18039 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18040 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18041 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18042 | |
| 18043 | TestCompletionCallback callback; |
| 18044 | |
| 18045 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18046 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18047 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18048 | |
| 18049 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18050 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18051 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18052 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18053 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18054 | } |
| 18055 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18056 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18057 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18058 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18059 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18060 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18061 | |
| 18062 | HttpRequestInfo request; |
| 18063 | request.method = "POST"; |
| 18064 | request.url = GURL("http://www.foo.com/"); |
| 18065 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18066 | request.traffic_annotation = |
| 18067 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18068 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18069 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18070 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18071 | MockWrite data_writes[] = { |
| 18072 | MockWrite("POST / HTTP/1.1\r\n" |
| 18073 | "Host: www.foo.com\r\n" |
| 18074 | "Connection: keep-alive\r\n" |
| 18075 | "Content-Length: 3\r\n\r\n"), |
| 18076 | MockWrite("foo"), |
| 18077 | }; |
| 18078 | |
| 18079 | MockRead data_reads[] = { |
| 18080 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 18081 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18082 | MockRead(SYNCHRONOUS, OK), |
| 18083 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18084 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18085 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18086 | |
| 18087 | TestCompletionCallback callback; |
| 18088 | |
| 18089 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18090 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18091 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18092 | |
| 18093 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18094 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18095 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18096 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18097 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18098 | } |
| 18099 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18100 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18101 | ChunkedUploadDataStream upload_data_stream(0); |
| 18102 | |
| 18103 | HttpRequestInfo request; |
| 18104 | request.method = "POST"; |
| 18105 | request.url = GURL("http://www.foo.com/"); |
| 18106 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18107 | request.traffic_annotation = |
| 18108 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18109 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18110 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18111 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18112 | // Send headers successfully, but get an error while sending the body. |
| 18113 | MockWrite data_writes[] = { |
| 18114 | MockWrite("POST / HTTP/1.1\r\n" |
| 18115 | "Host: www.foo.com\r\n" |
| 18116 | "Connection: keep-alive\r\n" |
| 18117 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 18118 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 18119 | }; |
| 18120 | |
| 18121 | MockRead data_reads[] = { |
| 18122 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18123 | MockRead(SYNCHRONOUS, OK), |
| 18124 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18125 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18126 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18127 | |
| 18128 | TestCompletionCallback callback; |
| 18129 | |
| 18130 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18131 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18132 | |
| 18133 | base::RunLoop().RunUntilIdle(); |
| 18134 | upload_data_stream.AppendData("f", 1, false); |
| 18135 | |
| 18136 | base::RunLoop().RunUntilIdle(); |
| 18137 | upload_data_stream.AppendData("oo", 2, true); |
| 18138 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18139 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18140 | |
| 18141 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18142 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18143 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18144 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18145 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18146 | } |
| 18147 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18148 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 18149 | const std::string& accept_encoding, |
| 18150 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18151 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18152 | bool should_match) { |
| 18153 | HttpRequestInfo request; |
| 18154 | request.method = "GET"; |
| 18155 | request.url = GURL("http://www.foo.com/"); |
| 18156 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 18157 | accept_encoding); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18158 | request.traffic_annotation = |
| 18159 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18160 | |
| 18161 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 18162 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18163 | // Send headers successfully, but get an error while sending the body. |
| 18164 | MockWrite data_writes[] = { |
| 18165 | MockWrite("GET / HTTP/1.1\r\n" |
| 18166 | "Host: www.foo.com\r\n" |
| 18167 | "Connection: keep-alive\r\n" |
| 18168 | "Accept-Encoding: "), |
| 18169 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 18170 | }; |
| 18171 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18172 | std::string response_code = "200 OK"; |
| 18173 | std::string extra; |
| 18174 | if (!location.empty()) { |
| 18175 | response_code = "301 Redirect\r\nLocation: "; |
| 18176 | response_code.append(location); |
| 18177 | } |
| 18178 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18179 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18180 | MockRead("HTTP/1.0 "), |
| 18181 | MockRead(response_code.data()), |
| 18182 | MockRead("\r\nContent-Encoding: "), |
| 18183 | MockRead(content_encoding.data()), |
| 18184 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18185 | MockRead(SYNCHRONOUS, OK), |
| 18186 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18187 | StaticSocketDataProvider data(data_reads, data_writes); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18188 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 18189 | |
| 18190 | TestCompletionCallback callback; |
| 18191 | |
| 18192 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18193 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18194 | |
| 18195 | rv = callback.WaitForResult(); |
| 18196 | if (should_match) { |
| 18197 | EXPECT_THAT(rv, IsOk()); |
| 18198 | } else { |
| 18199 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 18200 | } |
| 18201 | } |
| 18202 | |
| 18203 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18204 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18205 | } |
| 18206 | |
| 18207 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18208 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 18209 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18210 | } |
| 18211 | |
| 18212 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 18213 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18214 | "", false); |
| 18215 | } |
| 18216 | |
| 18217 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 18218 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 18219 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18220 | } |
| 18221 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18222 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 18223 | ProxyConfig proxy_config; |
| 18224 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18225 | proxy_config.set_pac_mandatory(true); |
| 18226 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18227 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18228 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18229 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Bence Béky | 8f9d7d395 | 2017-10-09 19:58:04 | [diff] [blame] | 18230 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18231 | |
| 18232 | HttpRequestInfo request; |
| 18233 | request.method = "GET"; |
| 18234 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18235 | request.traffic_annotation = |
| 18236 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18237 | |
| 18238 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18239 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18240 | |
| 18241 | TestCompletionCallback callback; |
| 18242 | |
| 18243 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18244 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18245 | EXPECT_THAT(callback.WaitForResult(), |
| 18246 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18247 | } |
| 18248 | |
| 18249 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 18250 | ProxyConfig proxy_config; |
| 18251 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18252 | proxy_config.set_pac_mandatory(true); |
| 18253 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 18254 | new MockAsyncProxyResolverFactory(false); |
| 18255 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18256 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18257 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18258 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18259 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18260 | HttpRequestInfo request; |
| 18261 | request.method = "GET"; |
| 18262 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18263 | request.traffic_annotation = |
| 18264 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18265 | |
| 18266 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18267 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18268 | |
| 18269 | TestCompletionCallback callback; |
| 18270 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18271 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18272 | |
| 18273 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 18274 | ERR_FAILED, &resolver); |
| 18275 | EXPECT_THAT(callback.WaitForResult(), |
| 18276 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18277 | } |
| 18278 | |
| 18279 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18280 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18281 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18282 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18283 | session_deps_.enable_quic = false; |
| 18284 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18285 | |
| 18286 | HttpRequestInfo request; |
| 18287 | request.method = "GET"; |
| 18288 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18289 | request.traffic_annotation = |
| 18290 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18291 | |
| 18292 | TestCompletionCallback callback; |
| 18293 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18294 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18295 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18296 | |
| 18297 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 18298 | } |
| 18299 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18300 | //----------------------------------------------------------------------------- |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18301 | // Reporting tests |
| 18302 | |
| 18303 | #if BUILDFLAG(ENABLE_REPORTING) |
| 18304 | class HttpNetworkTransactionReportingTest : public HttpNetworkTransactionTest { |
| 18305 | protected: |
| 18306 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18307 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18308 | auto test_reporting_context = std::make_unique<TestReportingContext>( |
| 18309 | &clock_, &tick_clock_, ReportingPolicy()); |
| 18310 | test_reporting_context_ = test_reporting_context.get(); |
| 18311 | session_deps_.reporting_service = |
| 18312 | ReportingService::CreateForTesting(std::move(test_reporting_context)); |
| 18313 | } |
| 18314 | |
| 18315 | TestReportingContext* reporting_context() const { |
| 18316 | return test_reporting_context_; |
| 18317 | } |
| 18318 | |
| 18319 | void clear_reporting_service() { |
| 18320 | session_deps_.reporting_service.reset(); |
| 18321 | test_reporting_context_ = nullptr; |
| 18322 | } |
| 18323 | |
| 18324 | // Makes an HTTPS request that should install a valid Reporting policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18325 | void RequestPolicy(CertStatus cert_status = 0) { |
| 18326 | HttpRequestInfo request; |
| 18327 | request.method = "GET"; |
| 18328 | request.url = GURL(url_); |
| 18329 | request.traffic_annotation = |
| 18330 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18331 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18332 | MockWrite data_writes[] = { |
| 18333 | MockWrite("GET / HTTP/1.1\r\n" |
| 18334 | "Host: www.example.org\r\n" |
| 18335 | "Connection: keep-alive\r\n\r\n"), |
| 18336 | }; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18337 | MockRead data_reads[] = { |
| 18338 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18339 | MockRead("Report-To: {\"group\": \"nel\", \"max_age\": 86400, " |
| 18340 | "\"endpoints\": [{\"url\": " |
| 18341 | "\"https://www.example.org/upload/\"}]}\r\n"), |
| 18342 | MockRead("\r\n"), |
| 18343 | MockRead("hello world"), |
| 18344 | MockRead(SYNCHRONOUS, OK), |
| 18345 | }; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18346 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18347 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18348 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18349 | |
| 18350 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18351 | if (request.url.SchemeIsCryptographic()) { |
| 18352 | ssl.ssl_info.cert = |
| 18353 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18354 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18355 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18356 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18357 | } |
| 18358 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18359 | TestCompletionCallback callback; |
| 18360 | auto session = CreateSession(&session_deps_); |
| 18361 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18362 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18363 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18364 | } |
| 18365 | |
| 18366 | protected: |
| 18367 | std::string url_ = "https://www.example.org/"; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18368 | |
| 18369 | private: |
| 18370 | TestReportingContext* test_reporting_context_; |
| 18371 | }; |
| 18372 | |
| 18373 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18374 | DontProcessReportToHeaderNoService) { |
| 18375 | base::HistogramTester histograms; |
| 18376 | clear_reporting_service(); |
| 18377 | RequestPolicy(); |
| 18378 | histograms.ExpectBucketCount( |
| 18379 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18380 | ReportingHeaderParser::HeaderOutcome::DISCARDED_NO_REPORTING_SERVICE, 1); |
| 18381 | } |
| 18382 | |
| 18383 | TEST_F(HttpNetworkTransactionReportingTest, DontProcessReportToHeaderHttp) { |
| 18384 | base::HistogramTester histograms; |
| 18385 | url_ = "http://www.example.org/"; |
| 18386 | RequestPolicy(); |
| 18387 | histograms.ExpectBucketCount( |
| 18388 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18389 | ReportingHeaderParser::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18390 | } |
| 18391 | |
| 18392 | TEST_F(HttpNetworkTransactionReportingTest, ProcessReportToHeaderHttps) { |
| 18393 | RequestPolicy(); |
| 18394 | std::vector<const ReportingClient*> clients; |
| 18395 | reporting_context()->cache()->GetClients(&clients); |
| 18396 | ASSERT_EQ(1u, clients.size()); |
| 18397 | const auto* client = clients[0]; |
| 18398 | EXPECT_EQ(url::Origin::Create(GURL("https://www.example.org/")), |
| 18399 | client->origin); |
| 18400 | EXPECT_EQ(GURL("https://www.example.org/upload/"), client->endpoint); |
| 18401 | EXPECT_EQ("nel", client->group); |
| 18402 | } |
| 18403 | |
| 18404 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18405 | DontProcessReportToHeaderInvalidHttps) { |
| 18406 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18407 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18408 | RequestPolicy(cert_status); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18409 | histograms.ExpectBucketCount( |
| 18410 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18411 | ReportingHeaderParser::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, 1); |
| 18412 | } |
| 18413 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 18414 | |
| 18415 | //----------------------------------------------------------------------------- |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18416 | // Network Error Logging tests |
| 18417 | |
| 18418 | #if BUILDFLAG(ENABLE_REPORTING) |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18419 | namespace { |
| 18420 | |
| 18421 | const char kUserAgent[] = "Mozilla/1.0"; |
| 18422 | const char kReferrer[] = "https://www.referrer.org/"; |
| 18423 | |
| 18424 | } // namespace |
| 18425 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18426 | class HttpNetworkTransactionNetworkErrorLoggingTest |
| 18427 | : public HttpNetworkTransactionTest { |
| 18428 | protected: |
| 18429 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18430 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18431 | auto network_error_logging_service = |
| 18432 | std::make_unique<TestNetworkErrorLoggingService>(); |
| 18433 | test_network_error_logging_service_ = network_error_logging_service.get(); |
| 18434 | session_deps_.network_error_logging_service = |
| 18435 | std::move(network_error_logging_service); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18436 | |
| 18437 | extra_headers_.SetHeader("User-Agent", kUserAgent); |
| 18438 | extra_headers_.SetHeader("Referer", kReferrer); |
| 18439 | |
| 18440 | request_.method = "GET"; |
| 18441 | request_.url = GURL(url_); |
| 18442 | request_.extra_headers = extra_headers_; |
| 18443 | request_.reporting_upload_depth = reporting_upload_depth_; |
| 18444 | request_.traffic_annotation = |
| 18445 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18446 | } |
| 18447 | |
| 18448 | TestNetworkErrorLoggingService* network_error_logging_service() const { |
| 18449 | return test_network_error_logging_service_; |
| 18450 | } |
| 18451 | |
| 18452 | void clear_network_error_logging_service() { |
| 18453 | session_deps_.network_error_logging_service.reset(); |
| 18454 | test_network_error_logging_service_ = nullptr; |
| 18455 | } |
| 18456 | |
| 18457 | // Makes an HTTPS request that should install a valid NEL policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18458 | void RequestPolicy(CertStatus cert_status = 0) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18459 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18460 | MockWrite data_writes[] = { |
| 18461 | MockWrite("GET / HTTP/1.1\r\n" |
| 18462 | "Host: www.example.org\r\n" |
| 18463 | "Connection: keep-alive\r\n"), |
| 18464 | MockWrite(ASYNC, extra_header_string.data(), |
| 18465 | extra_header_string.size()), |
| 18466 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18467 | MockRead data_reads[] = { |
| 18468 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18469 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 18470 | MockRead("\r\n"), |
| 18471 | MockRead("hello world"), |
| 18472 | MockRead(SYNCHRONOUS, OK), |
| 18473 | }; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18474 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18475 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18476 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18477 | |
| 18478 | SSLSocketDataProvider ssl(ASYNC, OK); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18479 | if (request_.url.SchemeIsCryptographic()) { |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18480 | ssl.ssl_info.cert = |
| 18481 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18482 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18483 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18484 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18485 | } |
| 18486 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18487 | TestCompletionCallback callback; |
| 18488 | auto session = CreateSession(&session_deps_); |
| 18489 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18490 | int rv = trans.Start(&request_, callback.callback(), NetLogWithSource()); |
| 18491 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18492 | |
| 18493 | std::string response_data; |
| 18494 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 18495 | EXPECT_EQ("hello world", response_data); |
| 18496 | } |
| 18497 | |
| 18498 | void CheckReport(size_t index, |
| 18499 | int status_code, |
| 18500 | int error_type, |
| 18501 | IPAddress server_ip = IPAddress::IPv4Localhost()) { |
| 18502 | ASSERT_LT(index, network_error_logging_service()->errors().size()); |
| 18503 | |
| 18504 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18505 | network_error_logging_service()->errors()[index]; |
| 18506 | EXPECT_EQ(url_, error.uri); |
| 18507 | EXPECT_EQ(kReferrer, error.referrer); |
| 18508 | EXPECT_EQ(kUserAgent, error.user_agent); |
| 18509 | EXPECT_EQ(server_ip, error.server_ip); |
| 18510 | EXPECT_EQ("http/1.1", error.protocol); |
| 18511 | EXPECT_EQ("GET", error.method); |
| 18512 | EXPECT_EQ(status_code, error.status_code); |
| 18513 | EXPECT_EQ(error_type, error.type); |
| 18514 | EXPECT_EQ(0, error.reporting_upload_depth); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18515 | } |
| 18516 | |
| 18517 | protected: |
| 18518 | std::string url_ = "https://www.example.org/"; |
| 18519 | CertStatus cert_status_ = 0; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18520 | HttpRequestInfo request_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18521 | HttpRequestHeaders extra_headers_; |
| 18522 | int reporting_upload_depth_ = 0; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18523 | |
| 18524 | private: |
| 18525 | TestNetworkErrorLoggingService* test_network_error_logging_service_; |
| 18526 | }; |
| 18527 | |
| 18528 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18529 | DontProcessNelHeaderNoService) { |
| 18530 | base::HistogramTester histograms; |
| 18531 | clear_network_error_logging_service(); |
| 18532 | RequestPolicy(); |
| 18533 | histograms.ExpectBucketCount( |
| 18534 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18535 | NetworkErrorLoggingService::HeaderOutcome:: |
| 18536 | DISCARDED_NO_NETWORK_ERROR_LOGGING_SERVICE, |
| 18537 | 1); |
| 18538 | } |
| 18539 | |
| 18540 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18541 | DontProcessNelHeaderHttp) { |
| 18542 | base::HistogramTester histograms; |
| 18543 | url_ = "http://www.example.org/"; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18544 | request_.url = GURL(url_); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18545 | RequestPolicy(); |
| 18546 | histograms.ExpectBucketCount( |
| 18547 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18548 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18549 | } |
| 18550 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 18551 | // Don't set NEL policies received on a proxied connection. |
| 18552 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18553 | DontProcessNelHeaderProxy) { |
| 18554 | session_deps_.proxy_resolution_service = |
| 18555 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18556 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18557 | BoundTestNetLog log; |
| 18558 | session_deps_.net_log = log.bound().net_log(); |
| 18559 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18560 | |
| 18561 | HttpRequestInfo request; |
| 18562 | request.method = "GET"; |
| 18563 | request.url = GURL("https://www.example.org/"); |
| 18564 | request.traffic_annotation = |
| 18565 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18566 | |
| 18567 | // Since we have proxy, should try to establish tunnel. |
| 18568 | MockWrite data_writes1[] = { |
| 18569 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 18570 | "Host: www.example.org:443\r\n" |
| 18571 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 18572 | |
| 18573 | MockWrite("GET / HTTP/1.1\r\n" |
| 18574 | "Host: www.example.org\r\n" |
| 18575 | "Connection: keep-alive\r\n\r\n"), |
| 18576 | }; |
| 18577 | |
| 18578 | MockRead data_reads1[] = { |
| 18579 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 18580 | |
| 18581 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 18582 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 18583 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18584 | MockRead("Content-Length: 100\r\n\r\n"), |
| 18585 | MockRead(SYNCHRONOUS, OK), |
| 18586 | }; |
| 18587 | |
| 18588 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18589 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18590 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18591 | ssl.ssl_info.cert = |
| 18592 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18593 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 18594 | ssl.ssl_info.cert_status = 0; |
| 18595 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18596 | |
| 18597 | TestCompletionCallback callback1; |
| 18598 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18599 | |
| 18600 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
| 18601 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18602 | |
| 18603 | rv = callback1.WaitForResult(); |
| 18604 | EXPECT_THAT(rv, IsOk()); |
| 18605 | |
| 18606 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 18607 | ASSERT_TRUE(response); |
| 18608 | EXPECT_EQ(200, response->headers->response_code()); |
| 18609 | EXPECT_TRUE(response->was_fetched_via_proxy); |
| 18610 | |
| 18611 | // No NEL header was set. |
| 18612 | EXPECT_EQ(0u, network_error_logging_service()->headers().size()); |
| 18613 | } |
| 18614 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18615 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ProcessNelHeaderHttps) { |
| 18616 | RequestPolicy(); |
| 18617 | ASSERT_EQ(1u, network_error_logging_service()->headers().size()); |
| 18618 | const auto& header = network_error_logging_service()->headers()[0]; |
| 18619 | EXPECT_EQ(url::Origin::Create(GURL("https://www.example.org/")), |
| 18620 | header.origin); |
| 18621 | EXPECT_EQ(IPAddress::IPv4Localhost(), header.received_ip_address); |
| 18622 | EXPECT_EQ("{\"report_to\": \"nel\", \"max_age\": 86400}", header.value); |
| 18623 | } |
| 18624 | |
| 18625 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18626 | DontProcessNelHeaderInvalidHttps) { |
| 18627 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18628 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18629 | RequestPolicy(cert_status); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18630 | histograms.ExpectBucketCount( |
| 18631 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18632 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, |
| 18633 | 1); |
| 18634 | } |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18635 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18636 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, CreateReportSuccess) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18637 | RequestPolicy(); |
| 18638 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18639 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 18640 | } |
| 18641 | |
| 18642 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18643 | CreateReportErrorAfterStart) { |
| 18644 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18645 | auto trans = |
| 18646 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18647 | |
| 18648 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
| 18649 | StaticSocketDataProvider data; |
| 18650 | data.set_connect_data(mock_connect); |
| 18651 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18652 | |
| 18653 | TestCompletionCallback callback; |
| 18654 | |
| 18655 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18656 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 18657 | |
| 18658 | trans.reset(); |
| 18659 | |
| 18660 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18661 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 18662 | IPAddress() /* server_ip */); |
| 18663 | } |
| 18664 | |
| 18665 | // Same as above except the error is ASYNC |
| 18666 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18667 | CreateReportErrorAfterStartAsync) { |
| 18668 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18669 | auto trans = |
| 18670 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18671 | |
| 18672 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
| 18673 | StaticSocketDataProvider data; |
| 18674 | data.set_connect_data(mock_connect); |
| 18675 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18676 | |
| 18677 | TestCompletionCallback callback; |
| 18678 | |
| 18679 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18680 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 18681 | |
| 18682 | trans.reset(); |
| 18683 | |
| 18684 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18685 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 18686 | IPAddress() /* server_ip */); |
| 18687 | } |
| 18688 | |
| 18689 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18690 | CreateReportReadBodyError) { |
| 18691 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18692 | MockWrite data_writes[] = { |
| 18693 | MockWrite("GET / HTTP/1.1\r\n" |
| 18694 | "Host: www.example.org\r\n" |
| 18695 | "Connection: keep-alive\r\n"), |
| 18696 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18697 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18698 | MockRead data_reads[] = { |
| 18699 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18700 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 18701 | MockRead("hello world"), |
| 18702 | MockRead(SYNCHRONOUS, OK), |
| 18703 | }; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18704 | |
| 18705 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18706 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 18707 | |
| 18708 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18709 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18710 | |
| 18711 | // Log start time |
| 18712 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18713 | |
| 18714 | TestCompletionCallback callback; |
| 18715 | auto session = CreateSession(&session_deps_); |
| 18716 | auto trans = |
| 18717 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18718 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18719 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18720 | |
| 18721 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18722 | ASSERT_TRUE(response); |
| 18723 | |
| 18724 | EXPECT_TRUE(response->headers); |
| 18725 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 18726 | |
| 18727 | std::string response_data; |
| 18728 | rv = ReadTransaction(trans.get(), &response_data); |
| 18729 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 18730 | |
| 18731 | trans.reset(); |
| 18732 | |
| 18733 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18734 | |
| 18735 | CheckReport(0 /* index */, 200 /* status_code */, |
| 18736 | ERR_CONTENT_LENGTH_MISMATCH); |
| 18737 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18738 | network_error_logging_service()->errors()[0]; |
| 18739 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 18740 | } |
| 18741 | |
| 18742 | // Same as above except the final read is ASYNC. |
| 18743 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18744 | CreateReportReadBodyErrorAsync) { |
| 18745 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18746 | MockWrite data_writes[] = { |
| 18747 | MockWrite("GET / HTTP/1.1\r\n" |
| 18748 | "Host: www.example.org\r\n" |
| 18749 | "Connection: keep-alive\r\n"), |
| 18750 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18751 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18752 | MockRead data_reads[] = { |
| 18753 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18754 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 18755 | MockRead("hello world"), |
| 18756 | MockRead(ASYNC, OK), |
| 18757 | }; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18758 | |
| 18759 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18760 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 18761 | |
| 18762 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18763 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18764 | |
| 18765 | // Log start time |
| 18766 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18767 | |
| 18768 | TestCompletionCallback callback; |
| 18769 | auto session = CreateSession(&session_deps_); |
| 18770 | auto trans = |
| 18771 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18772 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18773 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18774 | |
| 18775 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18776 | ASSERT_TRUE(response); |
| 18777 | |
| 18778 | EXPECT_TRUE(response->headers); |
| 18779 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 18780 | |
| 18781 | std::string response_data; |
| 18782 | rv = ReadTransaction(trans.get(), &response_data); |
| 18783 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 18784 | |
| 18785 | trans.reset(); |
| 18786 | |
| 18787 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18788 | |
| 18789 | CheckReport(0 /* index */, 200 /* status_code */, |
| 18790 | ERR_CONTENT_LENGTH_MISMATCH); |
| 18791 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18792 | network_error_logging_service()->errors()[0]; |
| 18793 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 18794 | } |
| 18795 | |
| 18796 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18797 | CreateReportRestartWithAuth) { |
| 18798 | std::string extra_header_string = extra_headers_.ToString(); |
| 18799 | static const base::TimeDelta kSleepDuration = |
| 18800 | base::TimeDelta::FromMilliseconds(10); |
| 18801 | |
| 18802 | MockWrite data_writes1[] = { |
| 18803 | MockWrite("GET / HTTP/1.1\r\n" |
| 18804 | "Host: www.example.org\r\n" |
| 18805 | "Connection: keep-alive\r\n"), |
| 18806 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18807 | }; |
| 18808 | |
| 18809 | MockRead data_reads1[] = { |
| 18810 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 18811 | // Give a couple authenticate options (only the middle one is actually |
| 18812 | // supported). |
| 18813 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 18814 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 18815 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 18816 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18817 | // Large content-length -- won't matter, as connection will be reset. |
| 18818 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 18819 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 18820 | }; |
| 18821 | |
| 18822 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18823 | // be issuing -- the final header line contains the credentials. |
| 18824 | MockWrite data_writes2[] = { |
| 18825 | MockWrite("GET / HTTP/1.1\r\n" |
| 18826 | "Host: www.example.org\r\n" |
| 18827 | "Connection: keep-alive\r\n" |
| 18828 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 18829 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18830 | }; |
| 18831 | |
| 18832 | // Lastly, the server responds with the actual content. |
| 18833 | MockRead data_reads2[] = { |
| 18834 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 18835 | MockRead("hello world"), |
| 18836 | MockRead(SYNCHRONOUS, OK), |
| 18837 | }; |
| 18838 | |
| 18839 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18840 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 18841 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18842 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18843 | |
| 18844 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18845 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18846 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18847 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18848 | |
| 18849 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18850 | base::TimeTicks restart_time; |
| 18851 | |
| 18852 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18853 | auto trans = |
| 18854 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18855 | |
| 18856 | TestCompletionCallback callback1; |
| 18857 | |
| 18858 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18859 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18860 | |
| 18861 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18862 | |
| 18863 | TestCompletionCallback callback2; |
| 18864 | |
| 18865 | // Wait 10 ms then restart with auth |
| 18866 | FastForwardBy(kSleepDuration); |
| 18867 | restart_time = base::TimeTicks::Now(); |
| 18868 | rv = |
| 18869 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 18870 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18871 | |
| 18872 | std::string response_data; |
| 18873 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 18874 | EXPECT_EQ("hello world", response_data); |
| 18875 | |
| 18876 | trans.reset(); |
| 18877 | |
| 18878 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 18879 | // retry. Note that we don't report the error draining the body, as the first |
| 18880 | // request already generated a report for the auth challenge. |
| 18881 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 18882 | |
| 18883 | // Check error report contents |
| 18884 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 18885 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 18886 | |
| 18887 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 18888 | network_error_logging_service()->errors()[0]; |
| 18889 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 18890 | network_error_logging_service()->errors()[1]; |
| 18891 | |
| 18892 | // Sanity-check elapsed time values |
| 18893 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 18894 | // Check that the start time is refreshed when restarting with auth. |
| 18895 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 18896 | } |
| 18897 | |
| 18898 | // Same as above, except draining the body before restarting fails |
| 18899 | // asynchronously. |
| 18900 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18901 | CreateReportRestartWithAuthAsync) { |
| 18902 | std::string extra_header_string = extra_headers_.ToString(); |
| 18903 | static const base::TimeDelta kSleepDuration = |
| 18904 | base::TimeDelta::FromMilliseconds(10); |
| 18905 | |
| 18906 | MockWrite data_writes1[] = { |
| 18907 | MockWrite("GET / HTTP/1.1\r\n" |
| 18908 | "Host: www.example.org\r\n" |
| 18909 | "Connection: keep-alive\r\n"), |
| 18910 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18911 | }; |
| 18912 | |
| 18913 | MockRead data_reads1[] = { |
| 18914 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 18915 | // Give a couple authenticate options (only the middle one is actually |
| 18916 | // supported). |
| 18917 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 18918 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 18919 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 18920 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18921 | // Large content-length -- won't matter, as connection will be reset. |
| 18922 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 18923 | MockRead(ASYNC, ERR_FAILED), |
| 18924 | }; |
| 18925 | |
| 18926 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18927 | // be issuing -- the final header line contains the credentials. |
| 18928 | MockWrite data_writes2[] = { |
| 18929 | MockWrite("GET / HTTP/1.1\r\n" |
| 18930 | "Host: www.example.org\r\n" |
| 18931 | "Connection: keep-alive\r\n" |
| 18932 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 18933 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18934 | }; |
| 18935 | |
| 18936 | // Lastly, the server responds with the actual content. |
| 18937 | MockRead data_reads2[] = { |
| 18938 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 18939 | MockRead("hello world"), |
| 18940 | MockRead(SYNCHRONOUS, OK), |
| 18941 | }; |
| 18942 | |
| 18943 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18944 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 18945 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18946 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18947 | |
| 18948 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18949 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18950 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18951 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18952 | |
| 18953 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18954 | base::TimeTicks restart_time; |
| 18955 | |
| 18956 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18957 | auto trans = |
| 18958 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18959 | |
| 18960 | TestCompletionCallback callback1; |
| 18961 | |
| 18962 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18963 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18964 | |
| 18965 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18966 | |
| 18967 | TestCompletionCallback callback2; |
| 18968 | |
| 18969 | // Wait 10 ms then restart with auth |
| 18970 | FastForwardBy(kSleepDuration); |
| 18971 | restart_time = base::TimeTicks::Now(); |
| 18972 | rv = |
| 18973 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 18974 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18975 | |
| 18976 | std::string response_data; |
| 18977 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 18978 | EXPECT_EQ("hello world", response_data); |
| 18979 | |
| 18980 | trans.reset(); |
| 18981 | |
| 18982 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 18983 | // retry. Note that we don't report the error draining the body, as the first |
| 18984 | // request already generated a report for the auth challenge. |
| 18985 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 18986 | |
| 18987 | // Check error report contents |
| 18988 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 18989 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 18990 | |
| 18991 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 18992 | network_error_logging_service()->errors()[0]; |
| 18993 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 18994 | network_error_logging_service()->errors()[1]; |
| 18995 | |
| 18996 | // Sanity-check elapsed time values |
| 18997 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 18998 | // Check that the start time is refreshed when restarting with auth. |
| 18999 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 19000 | } |
| 19001 | |
| 19002 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19003 | CreateReportRetryKeepAliveConnectionReset) { |
| 19004 | std::string extra_header_string = extra_headers_.ToString(); |
| 19005 | MockWrite data_writes1[] = { |
| 19006 | MockWrite("GET / HTTP/1.1\r\n" |
| 19007 | "Host: www.example.org\r\n" |
| 19008 | "Connection: keep-alive\r\n"), |
| 19009 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19010 | MockWrite("GET / HTTP/1.1\r\n" |
| 19011 | "Host: www.example.org\r\n" |
| 19012 | "Connection: keep-alive\r\n"), |
| 19013 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19014 | }; |
| 19015 | |
| 19016 | MockRead data_reads1[] = { |
| 19017 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19018 | MockRead("hello"), |
| 19019 | // Connection is reset |
| 19020 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 19021 | }; |
| 19022 | |
| 19023 | // Successful retry |
| 19024 | MockRead data_reads2[] = { |
| 19025 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19026 | MockRead("world"), |
| 19027 | MockRead(ASYNC, OK), |
| 19028 | }; |
| 19029 | |
| 19030 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19031 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 19032 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19033 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19034 | |
| 19035 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 19036 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 19037 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 19038 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 19039 | |
| 19040 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19041 | auto trans1 = |
| 19042 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19043 | |
| 19044 | TestCompletionCallback callback1; |
| 19045 | |
| 19046 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 19047 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19048 | |
| 19049 | std::string response_data; |
| 19050 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19051 | EXPECT_EQ("hello", response_data); |
| 19052 | |
| 19053 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19054 | |
| 19055 | auto trans2 = |
| 19056 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19057 | |
| 19058 | TestCompletionCallback callback2; |
| 19059 | |
| 19060 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 19061 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19062 | |
| 19063 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19064 | EXPECT_EQ("world", response_data); |
| 19065 | |
| 19066 | trans1.reset(); |
| 19067 | trans2.reset(); |
| 19068 | |
| 19069 | // One OK report from first request, then a ERR_CONNECTION_RESET report from |
| 19070 | // the second request, then an OK report from the successful retry. |
| 19071 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19072 | |
| 19073 | // Check error report contents |
| 19074 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19075 | CheckReport(1 /* index */, 0 /* status_code */, ERR_CONNECTION_RESET); |
| 19076 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 19077 | } |
| 19078 | |
| 19079 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19080 | CreateReportRetryKeepAlive408) { |
| 19081 | std::string extra_header_string = extra_headers_.ToString(); |
| 19082 | MockWrite data_writes1[] = { |
| 19083 | MockWrite("GET / HTTP/1.1\r\n" |
| 19084 | "Host: www.example.org\r\n" |
| 19085 | "Connection: keep-alive\r\n"), |
| 19086 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19087 | MockWrite("GET / HTTP/1.1\r\n" |
| 19088 | "Host: www.example.org\r\n" |
| 19089 | "Connection: keep-alive\r\n"), |
| 19090 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19091 | }; |
| 19092 | |
| 19093 | MockRead data_reads1[] = { |
| 19094 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19095 | MockRead("hello"), |
| 19096 | // 408 Request Timeout |
| 19097 | MockRead(SYNCHRONOUS, |
| 19098 | "HTTP/1.1 408 Request Timeout\r\n" |
| 19099 | "Connection: Keep-Alive\r\n" |
| 19100 | "Content-Length: 6\r\n\r\n" |
| 19101 | "Pickle"), |
| 19102 | }; |
| 19103 | |
| 19104 | // Successful retry |
| 19105 | MockRead data_reads2[] = { |
| 19106 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19107 | MockRead("world"), |
| 19108 | MockRead(ASYNC, OK), |
| 19109 | }; |
| 19110 | |
| 19111 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19112 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 19113 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19114 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19115 | |
| 19116 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 19117 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 19118 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 19119 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 19120 | |
| 19121 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19122 | auto trans1 = |
| 19123 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19124 | |
| 19125 | TestCompletionCallback callback1; |
| 19126 | |
| 19127 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 19128 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19129 | |
| 19130 | std::string response_data; |
| 19131 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19132 | EXPECT_EQ("hello", response_data); |
| 19133 | |
| 19134 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19135 | |
| 19136 | auto trans2 = |
| 19137 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19138 | |
| 19139 | TestCompletionCallback callback2; |
| 19140 | |
| 19141 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 19142 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19143 | |
| 19144 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19145 | EXPECT_EQ("world", response_data); |
| 19146 | |
| 19147 | trans1.reset(); |
| 19148 | trans2.reset(); |
| 19149 | |
| 19150 | // One 200 report from first request, then a 408 report from |
| 19151 | // the second request, then a 200 report from the successful retry. |
| 19152 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19153 | |
| 19154 | // Check error report contents |
| 19155 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19156 | CheckReport(1 /* index */, 408 /* status_code */, OK); |
| 19157 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 19158 | } |
| 19159 | |
| 19160 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19161 | CreateReportRetry421WithoutConnectionPooling) { |
| 19162 | // Two hosts resolve to the same IP address. |
| 19163 | const std::string ip_addr = "1.2.3.4"; |
| 19164 | IPAddress ip; |
| 19165 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 19166 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 19167 | |
| 19168 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
| 19169 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 19170 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 19171 | |
| 19172 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19173 | |
| 19174 | // Two requests on the first connection. |
| 19175 | spdy::SpdySerializedFrame req1( |
| 19176 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 19177 | spdy_util_.UpdateWithStreamDestruction(1); |
| 19178 | spdy::SpdySerializedFrame req2( |
| 19179 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 19180 | spdy::SpdySerializedFrame rst( |
| 19181 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
| 19182 | MockWrite writes1[] = { |
| 19183 | CreateMockWrite(req1, 0), |
| 19184 | CreateMockWrite(req2, 3), |
| 19185 | CreateMockWrite(rst, 6), |
| 19186 | }; |
| 19187 | |
| 19188 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 19189 | spdy::SpdySerializedFrame resp1( |
| 19190 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 19191 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 19192 | spdy::SpdyHeaderBlock response_headers; |
| 19193 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 19194 | spdy::SpdySerializedFrame resp2( |
| 19195 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 19196 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 19197 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 19198 | |
| 19199 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 19200 | SequencedSocketData data1(connect1, reads1, writes1); |
| 19201 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19202 | |
| 19203 | AddSSLSocketData(); |
| 19204 | |
| 19205 | // Retry the second request on a second connection. |
| 19206 | SpdyTestUtil spdy_util2; |
| 19207 | spdy::SpdySerializedFrame req3( |
| 19208 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 19209 | MockWrite writes2[] = { |
| 19210 | CreateMockWrite(req3, 0), |
| 19211 | }; |
| 19212 | |
| 19213 | spdy::SpdySerializedFrame resp3( |
| 19214 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 19215 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 19216 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 19217 | MockRead(ASYNC, 0, 3)}; |
| 19218 | |
| 19219 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 19220 | SequencedSocketData data2(connect2, reads2, writes2); |
| 19221 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19222 | |
| 19223 | AddSSLSocketData(); |
| 19224 | |
| 19225 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 19226 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 19227 | HostPortPair("mail.example.com", 443), base::nullopt); |
| 19228 | EXPECT_THAT(rv, IsOk()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19229 | |
| 19230 | HttpRequestInfo request1; |
| 19231 | request1.method = "GET"; |
| 19232 | request1.url = GURL("https://www.example.org/"); |
| 19233 | request1.load_flags = 0; |
| 19234 | request1.traffic_annotation = |
| 19235 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19236 | auto trans1 = |
| 19237 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19238 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 19239 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19240 | rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 19241 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19242 | |
| 19243 | const HttpResponseInfo* response = trans1->GetResponseInfo(); |
| 19244 | ASSERT_TRUE(response); |
| 19245 | ASSERT_TRUE(response->headers); |
| 19246 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19247 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19248 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19249 | std::string response_data; |
| 19250 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19251 | EXPECT_EQ("hello!", response_data); |
| 19252 | |
| 19253 | trans1.reset(); |
| 19254 | |
| 19255 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19256 | |
| 19257 | HttpRequestInfo request2; |
| 19258 | request2.method = "GET"; |
| 19259 | request2.url = GURL("https://mail.example.org/"); |
| 19260 | request2.load_flags = 0; |
| 19261 | request2.traffic_annotation = |
| 19262 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19263 | auto trans2 = |
| 19264 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19265 | |
| 19266 | BoundTestNetLog log; |
| 19267 | rv = trans2->Start(&request2, callback.callback(), log.bound()); |
| 19268 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19269 | |
| 19270 | response = trans2->GetResponseInfo(); |
| 19271 | ASSERT_TRUE(response); |
| 19272 | ASSERT_TRUE(response->headers); |
| 19273 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19274 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19275 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19276 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19277 | EXPECT_EQ("hello!", response_data); |
| 19278 | |
| 19279 | trans2.reset(); |
| 19280 | |
| 19281 | // One 200 report from the first request, then a 421 report from the |
| 19282 | // second request, then a 200 report from the successful retry. |
| 19283 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19284 | |
| 19285 | // Check error report contents |
| 19286 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 19287 | network_error_logging_service()->errors()[0]; |
| 19288 | EXPECT_EQ(GURL("https://www.example.org/"), error1.uri); |
| 19289 | EXPECT_TRUE(error1.referrer.is_empty()); |
| 19290 | EXPECT_EQ("", error1.user_agent); |
| 19291 | EXPECT_EQ(ip, error1.server_ip); |
| 19292 | EXPECT_EQ("h2", error1.protocol); |
| 19293 | EXPECT_EQ("GET", error1.method); |
| 19294 | EXPECT_EQ(200, error1.status_code); |
| 19295 | EXPECT_EQ(OK, error1.type); |
| 19296 | EXPECT_EQ(0, error1.reporting_upload_depth); |
| 19297 | |
| 19298 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 19299 | network_error_logging_service()->errors()[1]; |
| 19300 | EXPECT_EQ(GURL("https://mail.example.org/"), error2.uri); |
| 19301 | EXPECT_TRUE(error2.referrer.is_empty()); |
| 19302 | EXPECT_EQ("", error2.user_agent); |
| 19303 | EXPECT_EQ(ip, error2.server_ip); |
| 19304 | EXPECT_EQ("h2", error2.protocol); |
| 19305 | EXPECT_EQ("GET", error2.method); |
| 19306 | EXPECT_EQ(421, error2.status_code); |
| 19307 | EXPECT_EQ(OK, error2.type); |
| 19308 | EXPECT_EQ(0, error2.reporting_upload_depth); |
| 19309 | |
| 19310 | const NetworkErrorLoggingService::RequestDetails& error3 = |
| 19311 | network_error_logging_service()->errors()[2]; |
| 19312 | EXPECT_EQ(GURL("https://mail.example.org/"), error3.uri); |
| 19313 | EXPECT_TRUE(error3.referrer.is_empty()); |
| 19314 | EXPECT_EQ("", error3.user_agent); |
| 19315 | EXPECT_EQ(ip, error3.server_ip); |
| 19316 | EXPECT_EQ("h2", error3.protocol); |
| 19317 | EXPECT_EQ("GET", error3.method); |
| 19318 | EXPECT_EQ(200, error3.status_code); |
| 19319 | EXPECT_EQ(OK, error3.type); |
| 19320 | EXPECT_EQ(0, error3.reporting_upload_depth); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19321 | } |
| 19322 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19323 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19324 | CreateReportCancelAfterStart) { |
| 19325 | StaticSocketDataProvider data; |
| 19326 | data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING)); |
| 19327 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19328 | |
| 19329 | TestCompletionCallback callback; |
| 19330 | auto session = CreateSession(&session_deps_); |
| 19331 | auto trans = |
| 19332 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19333 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19334 | EXPECT_EQ(rv, ERR_IO_PENDING); |
| 19335 | |
| 19336 | // Cancel after start. |
| 19337 | trans.reset(); |
| 19338 | |
| 19339 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19340 | CheckReport(0 /* index */, 0 /* status_code */, ERR_ABORTED, |
| 19341 | IPAddress() /* server_ip */); |
| 19342 | } |
| 19343 | |
| 19344 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19345 | CreateReportCancelBeforeReadingBody) { |
| 19346 | std::string extra_header_string = extra_headers_.ToString(); |
| 19347 | MockWrite data_writes[] = { |
| 19348 | MockWrite("GET / HTTP/1.1\r\n" |
| 19349 | "Host: www.example.org\r\n" |
| 19350 | "Connection: keep-alive\r\n"), |
| 19351 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19352 | }; |
| 19353 | MockRead data_reads[] = { |
| 19354 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 19355 | MockRead("Content-Length: 100\r\n\r\n"), // Body is never read. |
| 19356 | }; |
| 19357 | |
| 19358 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19359 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19360 | |
| 19361 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19362 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19363 | |
| 19364 | TestCompletionCallback callback; |
| 19365 | auto session = CreateSession(&session_deps_); |
| 19366 | auto trans = |
| 19367 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19368 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19369 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19370 | |
| 19371 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19372 | ASSERT_TRUE(response); |
| 19373 | |
| 19374 | EXPECT_TRUE(response->headers); |
| 19375 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 19376 | |
| 19377 | // Cancel before reading the body. |
| 19378 | trans.reset(); |
| 19379 | |
| 19380 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19381 | CheckReport(0 /* index */, 200 /* status_code */, ERR_ABORTED); |
| 19382 | } |
| 19383 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19384 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportHttp) { |
| 19385 | base::HistogramTester histograms; |
| 19386 | RequestPolicy(); |
| 19387 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19388 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19389 | |
| 19390 | // Make HTTP request |
| 19391 | std::string extra_header_string = extra_headers_.ToString(); |
| 19392 | MockRead data_reads[] = { |
| 19393 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 19394 | MockRead("hello world"), |
| 19395 | MockRead(SYNCHRONOUS, OK), |
| 19396 | }; |
| 19397 | MockWrite data_writes[] = { |
| 19398 | MockWrite("GET / HTTP/1.1\r\n" |
| 19399 | "Host: www.example.org\r\n" |
| 19400 | "Connection: keep-alive\r\n"), |
| 19401 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19402 | }; |
| 19403 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19404 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19405 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19406 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19407 | // Insecure url |
| 19408 | url_ = "http://www.example.org/"; |
| 19409 | request_.url = GURL(url_); |
| 19410 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19411 | TestCompletionCallback callback; |
| 19412 | auto session = CreateSession(&session_deps_); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19413 | auto trans = |
| 19414 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19415 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19416 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19417 | |
| 19418 | std::string response_data; |
| 19419 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19420 | EXPECT_EQ("hello world", response_data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19421 | |
| 19422 | // Insecure request does not generate a report |
| 19423 | histograms.ExpectBucketCount( |
| 19424 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
Tsuyoshi Horo | 0b04223 | 2019-03-06 01:11:05 | [diff] [blame] | 19425 | NetworkErrorLoggingService::RequestOutcome::kDiscardedInsecureOrigin, 1); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19426 | |
| 19427 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19428 | } |
| 19429 | |
| 19430 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19431 | DontCreateReportHttpError) { |
| 19432 | base::HistogramTester histograms; |
| 19433 | RequestPolicy(); |
| 19434 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19435 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19436 | |
| 19437 | // Make HTTP request that fails |
| 19438 | MockRead data_reads[] = { |
| 19439 | MockRead("hello world"), |
| 19440 | MockRead(SYNCHRONOUS, OK), |
| 19441 | }; |
| 19442 | |
| 19443 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
| 19444 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19445 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19446 | url_ = "http://www.originwithoutpolicy.com:2000/"; |
| 19447 | request_.url = GURL(url_); |
| 19448 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19449 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19450 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19451 | auto trans = |
| 19452 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19453 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19454 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19455 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 19456 | |
| 19457 | // Insecure request does not generate a report, regardless of existence of a |
| 19458 | // policy for the origin. |
| 19459 | histograms.ExpectBucketCount( |
| 19460 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
Tsuyoshi Horo | 0b04223 | 2019-03-06 01:11:05 | [diff] [blame] | 19461 | NetworkErrorLoggingService::RequestOutcome::kDiscardedInsecureOrigin, 1); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19462 | |
| 19463 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19464 | } |
| 19465 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 19466 | // Don't report on proxy auth challenges, don't report if connecting through a |
| 19467 | // proxy. |
| 19468 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportProxy) { |
| 19469 | HttpRequestInfo request; |
| 19470 | request.method = "GET"; |
| 19471 | request.url = GURL("https://www.example.org/"); |
| 19472 | request.traffic_annotation = |
| 19473 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19474 | |
| 19475 | // Configure against proxy server "myproxy:70". |
| 19476 | session_deps_.proxy_resolution_service = |
| 19477 | ProxyResolutionService::CreateFixedFromPacResult( |
| 19478 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19479 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19480 | |
| 19481 | // Since we have proxy, should try to establish tunnel. |
| 19482 | MockWrite data_writes1[] = { |
| 19483 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19484 | "Host: www.example.org:443\r\n" |
| 19485 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 19486 | }; |
| 19487 | |
| 19488 | // The proxy responds to the connect with a 407, using a non-persistent |
| 19489 | // connection. |
| 19490 | MockRead data_reads1[] = { |
| 19491 | // No credentials. |
| 19492 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 19493 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 19494 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 19495 | }; |
| 19496 | |
| 19497 | MockWrite data_writes2[] = { |
| 19498 | // After calling trans->RestartWithAuth(), this is the request we should |
| 19499 | // be issuing -- the final header line contains the credentials. |
| 19500 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19501 | "Host: www.example.org:443\r\n" |
| 19502 | "Proxy-Connection: keep-alive\r\n" |
| 19503 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 19504 | |
| 19505 | MockWrite("GET / HTTP/1.1\r\n" |
| 19506 | "Host: www.example.org\r\n" |
| 19507 | "Connection: keep-alive\r\n\r\n"), |
| 19508 | }; |
| 19509 | |
| 19510 | MockRead data_reads2[] = { |
| 19511 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 19512 | |
| 19513 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19514 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 19515 | MockRead("Content-Length: 5\r\n\r\n"), |
| 19516 | MockRead(SYNCHRONOUS, "hello"), |
| 19517 | }; |
| 19518 | |
| 19519 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19520 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19521 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 19522 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19523 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19524 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19525 | |
| 19526 | TestCompletionCallback callback1; |
| 19527 | |
| 19528 | auto trans = |
| 19529 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19530 | |
| 19531 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
| 19532 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19533 | |
| 19534 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19535 | EXPECT_EQ(407, response->headers->response_code()); |
| 19536 | |
| 19537 | std::string response_data; |
| 19538 | rv = ReadTransaction(trans.get(), &response_data); |
| 19539 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
| 19540 | |
| 19541 | // No NEL report is generated for the 407. |
| 19542 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 19543 | |
| 19544 | TestCompletionCallback callback2; |
| 19545 | |
| 19546 | rv = |
| 19547 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 19548 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19549 | |
| 19550 | response = trans->GetResponseInfo(); |
| 19551 | EXPECT_EQ(200, response->headers->response_code()); |
| 19552 | |
| 19553 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19554 | EXPECT_EQ("hello", response_data); |
| 19555 | |
| 19556 | trans.reset(); |
| 19557 | |
| 19558 | // No NEL report is generated because we are behind a proxy. |
| 19559 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 19560 | } |
| 19561 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19562 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19563 | ReportContainsUploadDepth) { |
| 19564 | reporting_upload_depth_ = 7; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19565 | request_.reporting_upload_depth = reporting_upload_depth_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19566 | RequestPolicy(); |
| 19567 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19568 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19569 | network_error_logging_service()->errors()[0]; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19570 | EXPECT_EQ(7, error.reporting_upload_depth); |
| 19571 | } |
| 19572 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19573 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ReportElapsedTime) { |
| 19574 | std::string extra_header_string = extra_headers_.ToString(); |
| 19575 | static const base::TimeDelta kSleepDuration = |
| 19576 | base::TimeDelta::FromMilliseconds(10); |
| 19577 | |
| 19578 | std::vector<MockWrite> data_writes = { |
| 19579 | MockWrite(ASYNC, 0, |
| 19580 | "GET / HTTP/1.1\r\n" |
| 19581 | "Host: www.example.org\r\n" |
| 19582 | "Connection: keep-alive\r\n"), |
| 19583 | MockWrite(ASYNC, 1, extra_header_string.data()), |
| 19584 | }; |
| 19585 | |
| 19586 | std::vector<MockRead> data_reads = { |
| 19587 | // Write one byte of the status line, followed by a pause. |
| 19588 | MockRead(ASYNC, 2, "H"), |
| 19589 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 19590 | MockRead(ASYNC, 4, "TTP/1.1 200 OK\r\n\r\n"), |
| 19591 | MockRead(ASYNC, 5, "hello world"), |
| 19592 | MockRead(SYNCHRONOUS, OK, 6), |
| 19593 | }; |
| 19594 | |
| 19595 | SequencedSocketData data(data_reads, data_writes); |
| 19596 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19597 | |
| 19598 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19599 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19600 | |
| 19601 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19602 | |
| 19603 | auto trans = |
| 19604 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19605 | |
| 19606 | TestCompletionCallback callback; |
| 19607 | |
| 19608 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19609 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19610 | |
| 19611 | data.RunUntilPaused(); |
| 19612 | ASSERT_TRUE(data.IsPaused()); |
| 19613 | FastForwardBy(kSleepDuration); |
| 19614 | data.Resume(); |
| 19615 | |
| 19616 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19617 | |
| 19618 | std::string response_data; |
| 19619 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19620 | EXPECT_EQ("hello world", response_data); |
| 19621 | |
| 19622 | trans.reset(); |
| 19623 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19624 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19625 | |
| 19626 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19627 | |
| 19628 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19629 | network_error_logging_service()->errors()[0]; |
| 19630 | |
| 19631 | // Sanity-check elapsed time in error report |
| 19632 | EXPECT_EQ(kSleepDuration, error.elapsed_time); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19633 | } |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19634 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19635 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 19636 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 19637 | } // namespace net |