[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 5 | #include "net/http/http_network_transaction.h" |
| 6 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7 | #include <math.h> // ceil |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 8 | #include <stdarg.h> |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 9 | #include <stdint.h> |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11 | #include <limits> |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 12 | #include <set> |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 13 | #include <string> |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14 | #include <utility> |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 15 | #include <vector> |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 16 | |
Sebastien Marchand | 6d0558fd | 2019-01-25 16:49:37 | [diff] [blame] | 17 | #include "base/bind.h" |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 18 | #include "base/compiler_specific.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 19 | #include "base/files/file_path.h" |
thestig | d8df033 | 2014-09-04 06:33:29 | [diff] [blame] | 20 | #include "base/files/file_util.h" |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 21 | #include "base/json/json_writer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 22 | #include "base/logging.h" |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 23 | #include "base/memory/ptr_util.h" |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 24 | #include "base/memory/weak_ptr.h" |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 25 | #include "base/optional.h" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 26 | #include "base/run_loop.h" |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 27 | #include "base/stl_util.h" |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 28 | #include "base/strings/string_piece.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 29 | #include "base/strings/string_util.h" |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 30 | #include "base/strings/stringprintf.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 31 | #include "base/strings/utf_string_conversions.h" |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 32 | #include "base/test/metrics/histogram_tester.h" |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 33 | #include "base/test/scoped_task_environment.h" |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 34 | #include "base/test/simple_test_clock.h" |
| 35 | #include "base/test/simple_test_tick_clock.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 36 | #include "base/test/test_file_util.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 37 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 38 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 39 | #include "net/base/chunked_upload_data_stream.h" |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 40 | #include "net/base/completion_once_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 41 | #include "net/base/elements_upload_data_stream.h" |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 42 | #include "net/base/host_port_pair.h" |
Tsuyoshi Horo | 01faed6 | 2019-02-20 22:11:37 | [diff] [blame] | 43 | #include "net/base/ip_endpoint.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 44 | #include "net/base/load_timing_info.h" |
| 45 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 46 | #include "net/base/net_errors.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 47 | #include "net/base/proxy_delegate.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 48 | #include "net/base/proxy_server.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 49 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 50 | #include "net/base/test_completion_callback.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 51 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 52 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 53 | #include "net/base/upload_file_element_reader.h" |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 54 | #include "net/cert/cert_status_flags.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 55 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 56 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 57 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 58 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 59 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 60 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 61 | #include "net/http/http_auth_scheme.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 62 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 63 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 64 | #include "net/http/http_network_session_peer.h" |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 65 | #include "net/http/http_proxy_connect_job.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 66 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 67 | #include "net/http/http_response_info.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 68 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 69 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 70 | #include "net/http/http_stream_factory.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 71 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 72 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 73 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 74 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 75 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 76 | #include "net/log/test_net_log_entry.h" |
| 77 | #include "net/log/test_net_log_util.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 78 | #include "net/proxy_resolution/mock_proxy_resolver.h" |
| 79 | #include "net/proxy_resolution/proxy_config_service_fixed.h" |
| 80 | #include "net/proxy_resolution/proxy_info.h" |
Lily Houghton | ffe89daa0 | 2018-03-09 18:30:03 | [diff] [blame] | 81 | #include "net/proxy_resolution/proxy_resolution_service.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 82 | #include "net/proxy_resolution/proxy_resolver.h" |
| 83 | #include "net/proxy_resolution/proxy_resolver_factory.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 84 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 85 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 86 | #include "net/socket/client_socket_pool_manager.h" |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 87 | #include "net/socket/connect_job.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 88 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 89 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 90 | #include "net/socket/next_proto.h" |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 91 | #include "net/socket/socket_tag.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 92 | #include "net/socket/socket_test_util.h" |
Matt Menke | 4b412da | 2019-01-25 19:31:12 | [diff] [blame] | 93 | #include "net/socket/socks_connect_job.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 94 | #include "net/socket/ssl_client_socket.h" |
Bence Béky | 94658bf | 2018-05-11 19:22:58 | [diff] [blame] | 95 | #include "net/spdy/spdy_session.h" |
| 96 | #include "net/spdy/spdy_session_pool.h" |
| 97 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 98 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 99 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 100 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 101 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 102 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 103 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 104 | #include "net/test/test_data_directory.h" |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 105 | #include "net/test/test_with_scoped_task_environment.h" |
Victor Vasiliev | 27cc771 | 2019-01-24 11:50:14 | [diff] [blame] | 106 | #include "net/third_party/quiche/src/spdy/core/spdy_framer.h" |
[email protected] | baee31a | 2018-01-18 06:10:23 | [diff] [blame] | 107 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 108 | #include "net/url_request/static_http_user_agent_settings.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 109 | #include "net/websockets/websocket_handshake_stream_base.h" |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 110 | #include "net/websockets/websocket_test_util.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 111 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 112 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 113 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 114 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 115 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 116 | #if defined(NTLM_PORTABLE) |
| 117 | #include "base/base64.h" |
| 118 | #include "net/ntlm/ntlm_test_data.h" |
| 119 | #endif |
| 120 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 121 | #if BUILDFLAG(ENABLE_REPORTING) |
| 122 | #include "net/network_error_logging/network_error_logging_service.h" |
| 123 | #include "net/network_error_logging/network_error_logging_test_util.h" |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 124 | #include "net/reporting/reporting_cache.h" |
| 125 | #include "net/reporting/reporting_client.h" |
| 126 | #include "net/reporting/reporting_header_parser.h" |
| 127 | #include "net/reporting/reporting_service.h" |
| 128 | #include "net/reporting/reporting_test_util.h" |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 129 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 130 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 131 | using net::test::IsError; |
| 132 | using net::test::IsOk; |
| 133 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 134 | using base::ASCIIToUTF16; |
| 135 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 136 | //----------------------------------------------------------------------------- |
| 137 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 138 | namespace net { |
| 139 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 140 | namespace { |
| 141 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 142 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 143 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 144 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 145 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 146 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 147 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 148 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 149 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 150 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 151 | const base::string16 kSecond(ASCIIToUTF16("second")); |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 152 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 153 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 154 | const char kAlternativeServiceHttpHeader[] = |
| 155 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 156 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 157 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 158 | return session |
| 159 | ->GetSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 160 | ProxyServer::Direct()) |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 161 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 162 | } |
| 163 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 164 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 165 | return session |
| 166 | ->GetSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 167 | ProxyServer::Direct()) |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 168 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 169 | } |
| 170 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 171 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 172 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 173 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 174 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 175 | if (!params) |
| 176 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 177 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 178 | if (!params->GetList("headers", &header_list)) |
| 179 | return false; |
| 180 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 181 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 182 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 183 | return true; |
| 184 | } |
| 185 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 186 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 187 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 188 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 189 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 190 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 191 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 192 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 193 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 194 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 195 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 196 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 197 | |
| 198 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 199 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 200 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 201 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 202 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 203 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 204 | } |
| 205 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 206 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 207 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 208 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 209 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 210 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 211 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 212 | |
| 213 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 214 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 215 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 216 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 217 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 218 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 219 | load_timing_info.send_start); |
| 220 | |
| 221 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 222 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 223 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 224 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 225 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 226 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 230 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 231 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 232 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 233 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 234 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 235 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 236 | |
| 237 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 238 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 239 | load_timing_info.proxy_resolve_end); |
| 240 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 241 | load_timing_info.send_start); |
| 242 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 243 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 244 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 245 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 246 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 247 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 251 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 252 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 253 | int connect_timing_flags) { |
| 254 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 255 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 256 | |
| 257 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 258 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 259 | load_timing_info.proxy_resolve_end); |
| 260 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 261 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 262 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 263 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 264 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 265 | load_timing_info.send_start); |
| 266 | |
| 267 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 268 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 269 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 270 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 271 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 272 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 273 | } |
| 274 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 275 | // ProxyResolver that records URLs passed to it, and that can be told what |
| 276 | // result to return. |
| 277 | class CapturingProxyResolver : public ProxyResolver { |
| 278 | public: |
| 279 | CapturingProxyResolver() |
| 280 | : proxy_server_(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 80)) {} |
| 281 | ~CapturingProxyResolver() override = default; |
| 282 | |
| 283 | int GetProxyForURL(const GURL& url, |
| 284 | ProxyInfo* results, |
| 285 | CompletionOnceCallback callback, |
| 286 | std::unique_ptr<Request>* request, |
| 287 | const NetLogWithSource& net_log) override { |
| 288 | results->UseProxyServer(proxy_server_); |
| 289 | resolved_.push_back(url); |
| 290 | return OK; |
| 291 | } |
| 292 | |
| 293 | // Sets whether the resolver should use direct connections, instead of a |
| 294 | // proxy. |
| 295 | void set_proxy_server(ProxyServer proxy_server) { |
| 296 | proxy_server_ = proxy_server; |
| 297 | } |
| 298 | |
| 299 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 300 | |
| 301 | private: |
| 302 | std::vector<GURL> resolved_; |
| 303 | |
| 304 | ProxyServer proxy_server_; |
| 305 | |
| 306 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 307 | }; |
| 308 | |
| 309 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 310 | public: |
| 311 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 312 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 313 | |
| 314 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 315 | std::unique_ptr<ProxyResolver>* resolver, |
| 316 | CompletionOnceCallback callback, |
| 317 | std::unique_ptr<Request>* request) override { |
| 318 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
| 319 | return OK; |
| 320 | } |
| 321 | |
| 322 | private: |
| 323 | ProxyResolver* resolver_; |
| 324 | }; |
| 325 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 326 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 327 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 328 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 329 | } |
| 330 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 331 | class FailingProxyResolverFactory : public ProxyResolverFactory { |
| 332 | public: |
| 333 | FailingProxyResolverFactory() : ProxyResolverFactory(false) {} |
| 334 | |
| 335 | // ProxyResolverFactory override. |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 336 | int CreateProxyResolver(const scoped_refptr<PacFileData>& script_data, |
| 337 | std::unique_ptr<ProxyResolver>* result, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 338 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 339 | std::unique_ptr<Request>* request) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 340 | return ERR_PAC_SCRIPT_FAILED; |
| 341 | } |
| 342 | }; |
| 343 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 344 | class TestSSLConfigService : public SSLConfigService { |
| 345 | public: |
| 346 | explicit TestSSLConfigService(const SSLConfig& config) : config_(config) {} |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 347 | ~TestSSLConfigService() override = default; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 348 | |
| 349 | void GetSSLConfig(SSLConfig* config) override { *config = config_; } |
| 350 | |
Nick Harper | 89bc721 | 2018-07-31 19:07:57 | [diff] [blame] | 351 | bool CanShareConnectionWithClientCerts( |
| 352 | const std::string& hostname) const override { |
| 353 | return false; |
| 354 | } |
| 355 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 356 | private: |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 357 | SSLConfig config_; |
| 358 | }; |
| 359 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 360 | } // namespace |
| 361 | |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 362 | class HttpNetworkTransactionTest : public PlatformTest, |
| 363 | public WithScopedTaskEnvironment { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 364 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 365 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 366 | // Important to restore the per-pool limit first, since the pool limit must |
| 367 | // always be greater than group limit, and the tests reduce both limits. |
| 368 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 369 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 370 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 371 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 372 | } |
| 373 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 374 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 375 | HttpNetworkTransactionTest() |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 376 | : WithScopedTaskEnvironment( |
| 377 | base::test::ScopedTaskEnvironment::MainThreadType::IO_MOCK_TIME, |
| 378 | base::test::ScopedTaskEnvironment::NowSource:: |
| 379 | MAIN_THREAD_MOCK_TIME), |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 380 | dummy_connect_job_params_( |
| 381 | nullptr /* client_socket_factory */, |
| 382 | nullptr /* host_resolver */, |
Matt Menke | b88837e | 2019-03-20 11:50:40 | [diff] [blame] | 383 | nullptr /* http_auth_cache */, |
| 384 | nullptr /* http_auth_handler_factory */, |
| 385 | nullptr /* spdy_session_pool */, |
Matt Menke | b5fb42b | 2019-03-22 17:26:13 | [diff] [blame] | 386 | nullptr /* quic_supported_versions */, |
Matt Menke | b88837e | 2019-03-20 11:50:40 | [diff] [blame] | 387 | nullptr /* quic_stream_factory */, |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 388 | nullptr /* proxy_delegate */, |
| 389 | nullptr /* http_user_agent_settings */, |
| 390 | SSLClientSocketContext(), |
| 391 | SSLClientSocketContext(), |
| 392 | nullptr /* socket_performance_watcher_factory */, |
| 393 | nullptr /* network_quality_estimator */, |
| 394 | nullptr /* net_log */, |
| 395 | nullptr /* websocket_endpoint_lock_manager */), |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 396 | ssl_(ASYNC, OK), |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 397 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 398 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 399 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 400 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 401 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 402 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 403 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 404 | struct SimpleGetHelperResult { |
| 405 | int rv; |
| 406 | std::string status_line; |
| 407 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 408 | int64_t total_received_bytes; |
| 409 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 410 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 411 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 412 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 413 | }; |
| 414 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 415 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 416 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 417 | base::RunLoop().RunUntilIdle(); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 418 | // Set an initial delay to ensure that the first call to TimeTicks::Now() |
| 419 | // before incrementing the counter does not return a null value. |
| 420 | FastForwardBy(TimeDelta::FromSeconds(1)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 421 | } |
| 422 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 423 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 424 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 425 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 426 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 427 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 428 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 429 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 430 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 431 | } |
| 432 | |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 433 | void Check100ResponseTiming(bool use_spdy); |
| 434 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 435 | // Either |write_failure| specifies a write failure or |read_failure| |
| 436 | // specifies a read failure when using a reused socket. In either case, the |
| 437 | // failure should cause the network transaction to resend the request, and the |
| 438 | // other argument should be NULL. |
| 439 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 440 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 441 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 442 | // Either |write_failure| specifies a write failure or |read_failure| |
| 443 | // specifies a read failure when using a reused socket. In either case, the |
| 444 | // failure should cause the network transaction to resend the request, and the |
| 445 | // other argument should be NULL. |
| 446 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 447 | const MockRead* read_failure, |
| 448 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 449 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 450 | SimpleGetHelperResult SimpleGetHelperForData( |
| 451 | base::span<StaticSocketDataProvider*> providers) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 452 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 453 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 454 | HttpRequestInfo request; |
| 455 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 456 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 457 | request.traffic_annotation = |
| 458 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 459 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 460 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 461 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 462 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 463 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 464 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 465 | for (auto* provider : providers) { |
| 466 | session_deps_.socket_factory->AddSocketDataProvider(provider); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 467 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 468 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 469 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 470 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 471 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 472 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 473 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 474 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 475 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 476 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 477 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 478 | |
| 479 | // Even in the failure cases that use this function, connections are always |
| 480 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 481 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 482 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 483 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 484 | if (out.rv != OK) |
| 485 | return out; |
| 486 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 487 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 488 | // Can't use ASSERT_* inside helper functions like this, so |
| 489 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 490 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 491 | out.rv = ERR_UNEXPECTED; |
| 492 | return out; |
| 493 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 494 | out.status_line = response->headers->GetStatusLine(); |
| 495 | |
Tsuyoshi Horo | 01faed6 | 2019-02-20 22:11:37 | [diff] [blame] | 496 | EXPECT_EQ("127.0.0.1", response->remote_endpoint.ToStringWithoutPort()); |
| 497 | EXPECT_EQ(80, response->remote_endpoint.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 498 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 499 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 500 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 501 | EXPECT_EQ(got_endpoint, |
| 502 | out.remote_endpoint_after_start.address().size() > 0); |
| 503 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 504 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 505 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 506 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 507 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 508 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 509 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 510 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 511 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 512 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 513 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 514 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 515 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 516 | std::string line; |
| 517 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 518 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 519 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 520 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 521 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 522 | std::string value; |
| 523 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 524 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 525 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 526 | EXPECT_EQ("keep-alive", value); |
| 527 | |
| 528 | std::string response_headers; |
| 529 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 530 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 531 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 532 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 533 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 534 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 535 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 536 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 537 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 538 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 539 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 540 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 541 | SimpleGetHelperResult SimpleGetHelper(base::span<const MockRead> data_reads) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 542 | MockWrite data_writes[] = { |
| 543 | MockWrite("GET / HTTP/1.1\r\n" |
| 544 | "Host: www.example.org\r\n" |
| 545 | "Connection: keep-alive\r\n\r\n"), |
| 546 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 547 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 548 | StaticSocketDataProvider reads(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 549 | StaticSocketDataProvider* data[] = {&reads}; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 550 | SimpleGetHelperResult out = SimpleGetHelperForData(data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 551 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 552 | EXPECT_EQ(CountWriteBytes(data_writes), out.total_sent_bytes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 553 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 554 | } |
| 555 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 556 | void AddSSLSocketData() { |
| 557 | ssl_.next_proto = kProtoHTTP2; |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 558 | ssl_.ssl_info.cert = |
| 559 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 560 | ASSERT_TRUE(ssl_.ssl_info.cert); |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 561 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 562 | } |
| 563 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 564 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 565 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 566 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 567 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 568 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 569 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 570 | |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 571 | const CommonConnectJobParams dummy_connect_job_params_; |
| 572 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 573 | // These clocks are defined here, even though they're only used in the |
| 574 | // Reporting tests below, since they need to be destroyed after |
| 575 | // |session_deps_|. |
| 576 | base::SimpleTestClock clock_; |
| 577 | base::SimpleTestTickClock tick_clock_; |
| 578 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 579 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 580 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 581 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 582 | |
| 583 | // Original socket limits. Some tests set these. Safest to always restore |
| 584 | // them once each test has been run. |
| 585 | int old_max_group_sockets_; |
| 586 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 587 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 588 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 589 | namespace { |
| 590 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 591 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 592 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 593 | BeforeHeadersSentHandler() |
| 594 | : observed_before_headers_sent_with_proxy_(false), |
| 595 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 596 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 597 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 598 | HttpRequestHeaders* request_headers) { |
| 599 | observed_before_headers_sent_ = true; |
| 600 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 601 | !proxy_info.is_quic()) { |
| 602 | return; |
| 603 | } |
| 604 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 605 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 606 | } |
| 607 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 608 | bool observed_before_headers_sent_with_proxy() const { |
| 609 | return observed_before_headers_sent_with_proxy_; |
| 610 | } |
| 611 | |
| 612 | bool observed_before_headers_sent() const { |
| 613 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | std::string observed_proxy_server_uri() const { |
| 617 | return observed_proxy_server_uri_; |
| 618 | } |
| 619 | |
| 620 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 621 | bool observed_before_headers_sent_with_proxy_; |
| 622 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 623 | std::string observed_proxy_server_uri_; |
| 624 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 625 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 626 | }; |
| 627 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 628 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 629 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 630 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 631 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 632 | const int sizeof_row = strlen(row); |
| 633 | const int num_rows = static_cast<int>( |
| 634 | ceil(static_cast<float>(size) / sizeof_row)); |
| 635 | const int sizeof_data = num_rows * sizeof_row; |
| 636 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 637 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 638 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 639 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 640 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 641 | } |
| 642 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 643 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 644 | uint64_t MockGetMSTime() { |
| 645 | // Tue, 23 May 2017 20:13:07 +0000 |
| 646 | return 131400439870000000; |
| 647 | } |
| 648 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 649 | // Alternative functions that eliminate randomness and dependency on the local |
| 650 | // host name so that the generated NTLM messages are reproducible. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 651 | void MockGenerateRandom(uint8_t* output, size_t n) { |
| 652 | // This is set to 0xaa because the client challenge for testing in |
| 653 | // [MS-NLMP] Section 4.2.1 is 8 bytes of 0xaa. |
| 654 | memset(output, 0xaa, n); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 655 | } |
| 656 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 657 | std::string MockGetHostName() { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 658 | return ntlm::test::kHostnameAscii; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 659 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 660 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 661 | |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 662 | class CaptureGroupIdTransportSocketPool : public TransportClientSocketPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 663 | public: |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 664 | explicit CaptureGroupIdTransportSocketPool( |
| 665 | const CommonConnectJobParams* common_connect_job_params) |
| 666 | : TransportClientSocketPool(0, |
| 667 | 0, |
| 668 | base::TimeDelta(), |
| 669 | common_connect_job_params, |
| 670 | nullptr /* ssl_config_service */) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 671 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 672 | const ClientSocketPool::GroupId& last_group_id_received() const { |
| 673 | return last_group_id_; |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 674 | } |
| 675 | |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 676 | bool socket_requested() const { return socket_requested_; } |
| 677 | |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 678 | int RequestSocket( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 679 | const ClientSocketPool::GroupId& group_id, |
Matt Menke | bd12b7e | 2019-03-25 21:12:03 | [diff] [blame^] | 680 | scoped_refptr<ClientSocketPool::SocketParams> socket_params, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 681 | RequestPriority priority, |
| 682 | const SocketTag& socket_tag, |
| 683 | ClientSocketPool::RespectLimits respect_limits, |
| 684 | ClientSocketHandle* handle, |
| 685 | CompletionOnceCallback callback, |
| 686 | const ClientSocketPool::ProxyAuthCallback& proxy_auth_callback, |
| 687 | const NetLogWithSource& net_log) override { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 688 | last_group_id_ = group_id; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 689 | socket_requested_ = true; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 690 | return ERR_IO_PENDING; |
| 691 | } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 692 | void CancelRequest(const ClientSocketPool::GroupId& group_id, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 693 | ClientSocketHandle* handle) override {} |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 694 | void ReleaseSocket(const ClientSocketPool::GroupId& group_id, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 695 | std::unique_ptr<StreamSocket> socket, |
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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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())); |
| 3713 | |
| 3714 | TestCompletionCallback callback2; |
| 3715 | |
| 3716 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3717 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3718 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3719 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3720 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3721 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3722 | ASSERT_TRUE(response); |
| 3723 | ASSERT_TRUE(response->headers); |
| 3724 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3725 | EXPECT_EQ(407, response->headers->response_code()); |
| 3726 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3727 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3728 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3729 | |
| 3730 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3731 | // out of scope. |
| 3732 | session->CloseAllConnections(); |
| 3733 | } |
| 3734 | } |
| 3735 | |
| 3736 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3737 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3738 | // the case the server sends extra data on the original socket, so it can't be |
| 3739 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3740 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3741 | HttpRequestInfo request; |
| 3742 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3743 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3744 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3745 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3746 | request.traffic_annotation = |
| 3747 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3748 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3749 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3750 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3751 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3752 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3753 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3754 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3755 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3756 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3757 | // Since we have proxy, should try to establish tunnel. |
| 3758 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3759 | MockWrite(ASYNC, 0, |
| 3760 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3761 | "Host: www.example.org:443\r\n" |
| 3762 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3763 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3764 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3765 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3766 | // extra data, so the socket cannot be reused. |
| 3767 | MockRead data_reads1[] = { |
| 3768 | // No credentials. |
| 3769 | MockRead(ASYNC, 1, |
| 3770 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3771 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3772 | "Content-Length: 10\r\n\r\n"), |
| 3773 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3774 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3775 | }; |
| 3776 | |
| 3777 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3778 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3779 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3780 | MockWrite(ASYNC, 0, |
| 3781 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3782 | "Host: www.example.org:443\r\n" |
| 3783 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3784 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3785 | |
| 3786 | MockWrite(ASYNC, 2, |
| 3787 | "GET / HTTP/1.1\r\n" |
| 3788 | "Host: www.example.org\r\n" |
| 3789 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3790 | }; |
| 3791 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3792 | MockRead data_reads2[] = { |
| 3793 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3794 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3795 | MockRead(ASYNC, 3, |
| 3796 | "HTTP/1.1 200 OK\r\n" |
| 3797 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3798 | "Content-Length: 5\r\n\r\n"), |
| 3799 | // No response body because the test stops reading here. |
| 3800 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3801 | }; |
| 3802 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3803 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3804 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3805 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3806 | SequencedSocketData data2(data_reads2, data_writes2); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3807 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3808 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3809 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3810 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3811 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3812 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3813 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3814 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3815 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3816 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3817 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3818 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3819 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3820 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3821 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3822 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3823 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3824 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3825 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3826 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3827 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3828 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3829 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3830 | ASSERT_TRUE(response); |
| 3831 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3832 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3833 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3834 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3835 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3836 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3837 | LoadTimingInfo load_timing_info; |
| 3838 | // CONNECT requests and responses are handled at the connect job level, so |
| 3839 | // the transaction does not yet have a connection. |
| 3840 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3841 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3842 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3843 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3844 | rv = |
| 3845 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3846 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3847 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3848 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3849 | EXPECT_EQ(200, response->headers->response_code()); |
| 3850 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3851 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3852 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3853 | // The password prompt info should not be set. |
| 3854 | EXPECT_FALSE(response->auth_challenge); |
| 3855 | |
| 3856 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3857 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3858 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3859 | |
| 3860 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3861 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3862 | } |
| 3863 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3864 | // Test the case a proxy closes a socket while the challenge body is being |
| 3865 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3866 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3867 | HttpRequestInfo request; |
| 3868 | request.method = "GET"; |
| 3869 | request.url = GURL("https://www.example.org/"); |
| 3870 | // Ensure that proxy authentication is attempted even |
| 3871 | // when the no authentication data flag is set. |
| 3872 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3873 | request.traffic_annotation = |
| 3874 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3875 | |
| 3876 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3877 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3878 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3879 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3880 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3881 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3882 | |
| 3883 | // Since we have proxy, should try to establish tunnel. |
| 3884 | MockWrite data_writes1[] = { |
| 3885 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3886 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3887 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3888 | }; |
| 3889 | |
| 3890 | // The proxy responds to the connect with a 407, using a persistent |
| 3891 | // connection. |
| 3892 | MockRead data_reads1[] = { |
| 3893 | // No credentials. |
| 3894 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3895 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3896 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3897 | // Server hands up in the middle of the body. |
| 3898 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3899 | }; |
| 3900 | |
| 3901 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3902 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3903 | // be issuing -- the final header line contains the credentials. |
| 3904 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3905 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3906 | "Proxy-Connection: keep-alive\r\n" |
| 3907 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3908 | |
| 3909 | MockWrite("GET / HTTP/1.1\r\n" |
| 3910 | "Host: www.example.org\r\n" |
| 3911 | "Connection: keep-alive\r\n\r\n"), |
| 3912 | }; |
| 3913 | |
| 3914 | MockRead data_reads2[] = { |
| 3915 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3916 | |
| 3917 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3918 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3919 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3920 | MockRead(SYNCHRONOUS, "hello"), |
| 3921 | }; |
| 3922 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3923 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3924 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3925 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3926 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3927 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3928 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3929 | |
| 3930 | TestCompletionCallback callback; |
| 3931 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3932 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3933 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3934 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3935 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3936 | ASSERT_TRUE(response); |
| 3937 | ASSERT_TRUE(response->headers); |
| 3938 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3939 | EXPECT_EQ(407, response->headers->response_code()); |
| 3940 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3941 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3942 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3943 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3944 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3945 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3946 | ASSERT_TRUE(response); |
| 3947 | ASSERT_TRUE(response->headers); |
| 3948 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3949 | EXPECT_EQ(200, response->headers->response_code()); |
| 3950 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3951 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3952 | EXPECT_EQ("hello", body); |
| 3953 | } |
| 3954 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3955 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3956 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3957 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3958 | HttpRequestInfo request; |
| 3959 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3960 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3961 | request.traffic_annotation = |
| 3962 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3963 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3964 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3965 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3966 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3967 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3968 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3969 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3970 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3971 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3972 | // Since we have proxy, should try to establish tunnel. |
| 3973 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3974 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3975 | "Host: www.example.org:443\r\n" |
| 3976 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3977 | }; |
| 3978 | |
| 3979 | // The proxy responds to the connect with a 407. |
| 3980 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3981 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3982 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3983 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3984 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3985 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3986 | }; |
| 3987 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3988 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3989 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3990 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3991 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3992 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3993 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3994 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3995 | |
| 3996 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3997 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3998 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3999 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4000 | ASSERT_TRUE(response); |
| 4001 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4002 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4003 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4004 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4005 | |
| 4006 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4007 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4008 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 4009 | |
| 4010 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 4011 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4012 | } |
| 4013 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4014 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 4015 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4016 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4017 | HttpRequestInfo request; |
| 4018 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4019 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4020 | request.traffic_annotation = |
| 4021 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4022 | |
| 4023 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4024 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4025 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4026 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4027 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4028 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4029 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4030 | |
| 4031 | // Since we have proxy, should try to establish tunnel. |
| 4032 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4033 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4034 | "Host: www.example.org:443\r\n" |
| 4035 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4036 | }; |
| 4037 | |
| 4038 | // The proxy responds to the connect with a 407. |
| 4039 | MockRead data_reads[] = { |
| 4040 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4041 | MockRead("X-Foo: bar\r\n"), |
| 4042 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 4043 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4044 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4045 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4046 | }; |
| 4047 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4048 | StaticSocketDataProvider data(data_reads, data_writes); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4049 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4050 | |
| 4051 | TestCompletionCallback callback; |
| 4052 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4053 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4054 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4055 | |
| 4056 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4057 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4058 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4059 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4060 | ASSERT_TRUE(response); |
| 4061 | ASSERT_TRUE(response->headers); |
| 4062 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4063 | EXPECT_EQ(407, response->headers->response_code()); |
| 4064 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4065 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 4066 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 4067 | |
| 4068 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4069 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4070 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4071 | |
| 4072 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 4073 | session->CloseAllConnections(); |
| 4074 | } |
| 4075 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4076 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 4077 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4078 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4079 | HttpRequestInfo request; |
| 4080 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4081 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4082 | request.traffic_annotation = |
| 4083 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4084 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4085 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4086 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4087 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4088 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4089 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4090 | MockWrite( |
| 4091 | "GET / HTTP/1.1\r\n" |
| 4092 | "Host: www.example.org\r\n" |
| 4093 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4094 | }; |
| 4095 | |
| 4096 | MockRead data_reads1[] = { |
| 4097 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 4098 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4099 | // Large content-length -- won't matter, as connection will be reset. |
| 4100 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4101 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4102 | }; |
| 4103 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4104 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4105 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4106 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4107 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4108 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4109 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4110 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4111 | |
| 4112 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4113 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4114 | } |
| 4115 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4116 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 4117 | // through a non-authenticating proxy. The request should fail with |
| 4118 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 4119 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 4120 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 4121 | // response came from the proxy or the server, so it is treated as if the proxy |
| 4122 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4123 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4124 | HttpRequestInfo request; |
| 4125 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4126 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4127 | request.traffic_annotation = |
| 4128 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4129 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4130 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4131 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4132 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4133 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4134 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4135 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4136 | // Since we have proxy, should try to establish tunnel. |
| 4137 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4138 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4139 | "Host: www.example.org:443\r\n" |
| 4140 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4141 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4142 | MockWrite("GET / HTTP/1.1\r\n" |
| 4143 | "Host: www.example.org\r\n" |
| 4144 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4145 | }; |
| 4146 | |
| 4147 | MockRead data_reads1[] = { |
| 4148 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4149 | |
| 4150 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 4151 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4152 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4153 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4154 | }; |
| 4155 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4156 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4157 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4158 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4159 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4160 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4161 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4162 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4163 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4164 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4165 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4166 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4167 | |
| 4168 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4169 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 4170 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4171 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4172 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4173 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 4174 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4175 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4176 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4177 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 4178 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4179 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4180 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4181 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4182 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4183 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4184 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 4185 | HttpRequestInfo request; |
| 4186 | request.method = "GET"; |
| 4187 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4188 | request.traffic_annotation = |
| 4189 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4190 | |
| 4191 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4192 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4193 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4194 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4195 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4196 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4197 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4198 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4199 | mock_handler->set_allows_default_credentials(true); |
| 4200 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4201 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4202 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4203 | |
| 4204 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4205 | NetLog net_log; |
| 4206 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4207 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4208 | |
| 4209 | // Since we have proxy, should try to establish tunnel. |
| 4210 | MockWrite data_writes1[] = { |
| 4211 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4212 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4213 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4214 | }; |
| 4215 | |
| 4216 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4217 | // connection. |
| 4218 | MockRead data_reads1[] = { |
| 4219 | // No credentials. |
| 4220 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4221 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4222 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4223 | }; |
| 4224 | |
| 4225 | // Since the first connection couldn't be reused, need to establish another |
| 4226 | // once given credentials. |
| 4227 | MockWrite data_writes2[] = { |
| 4228 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4229 | // be issuing -- the final header line contains the credentials. |
| 4230 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4231 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4232 | "Proxy-Connection: keep-alive\r\n" |
| 4233 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4234 | |
| 4235 | MockWrite("GET / HTTP/1.1\r\n" |
| 4236 | "Host: www.example.org\r\n" |
| 4237 | "Connection: keep-alive\r\n\r\n"), |
| 4238 | }; |
| 4239 | |
| 4240 | MockRead data_reads2[] = { |
| 4241 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4242 | |
| 4243 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4244 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4245 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4246 | MockRead(SYNCHRONOUS, "hello"), |
| 4247 | }; |
| 4248 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4249 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4250 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4251 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4252 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4253 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4254 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4255 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4256 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4257 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4258 | |
| 4259 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4260 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4261 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4262 | |
| 4263 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4264 | ASSERT_TRUE(response); |
| 4265 | ASSERT_TRUE(response->headers); |
| 4266 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 4267 | EXPECT_EQ(407, response->headers->response_code()); |
| 4268 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4269 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4270 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4271 | |
| 4272 | LoadTimingInfo load_timing_info; |
| 4273 | // CONNECT requests and responses are handled at the connect job level, so |
| 4274 | // the transaction does not yet have a connection. |
| 4275 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4276 | |
| 4277 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4278 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4279 | response = trans->GetResponseInfo(); |
| 4280 | ASSERT_TRUE(response); |
| 4281 | ASSERT_TRUE(response->headers); |
| 4282 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4283 | EXPECT_EQ(200, response->headers->response_code()); |
| 4284 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4285 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4286 | |
| 4287 | // The password prompt info should not be set. |
| 4288 | EXPECT_FALSE(response->auth_challenge); |
| 4289 | |
| 4290 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4291 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4292 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4293 | |
| 4294 | trans.reset(); |
| 4295 | session->CloseAllConnections(); |
| 4296 | } |
| 4297 | |
| 4298 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4299 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4300 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4301 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4302 | HttpRequestInfo request; |
| 4303 | request.method = "GET"; |
| 4304 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4305 | request.traffic_annotation = |
| 4306 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4307 | |
| 4308 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4309 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4310 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4311 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4312 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4313 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4314 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4315 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4316 | mock_handler->set_allows_default_credentials(true); |
| 4317 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4318 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4319 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4320 | |
| 4321 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4322 | NetLog net_log; |
| 4323 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4324 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4325 | |
| 4326 | // Should try to establish tunnel. |
| 4327 | MockWrite data_writes1[] = { |
| 4328 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4329 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4330 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4331 | |
| 4332 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4333 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4334 | "Proxy-Connection: keep-alive\r\n" |
| 4335 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4336 | }; |
| 4337 | |
| 4338 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4339 | // connection. |
| 4340 | MockRead data_reads1[] = { |
| 4341 | // No credentials. |
| 4342 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4343 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4344 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4345 | }; |
| 4346 | |
| 4347 | // Since the first connection was closed, need to establish another once given |
| 4348 | // credentials. |
| 4349 | MockWrite data_writes2[] = { |
| 4350 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4351 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4352 | "Proxy-Connection: keep-alive\r\n" |
| 4353 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4354 | |
| 4355 | MockWrite("GET / HTTP/1.1\r\n" |
| 4356 | "Host: www.example.org\r\n" |
| 4357 | "Connection: keep-alive\r\n\r\n"), |
| 4358 | }; |
| 4359 | |
| 4360 | MockRead data_reads2[] = { |
| 4361 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4362 | |
| 4363 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4364 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4365 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4366 | MockRead(SYNCHRONOUS, "hello"), |
| 4367 | }; |
| 4368 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4369 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4370 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4371 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4372 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4373 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4374 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4375 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4376 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4377 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4378 | |
| 4379 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4380 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4381 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4382 | |
| 4383 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4384 | ASSERT_TRUE(response); |
| 4385 | ASSERT_TRUE(response->headers); |
| 4386 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4387 | EXPECT_EQ(407, response->headers->response_code()); |
| 4388 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4389 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4390 | EXPECT_FALSE(response->auth_challenge); |
| 4391 | |
| 4392 | LoadTimingInfo load_timing_info; |
| 4393 | // CONNECT requests and responses are handled at the connect job level, so |
| 4394 | // the transaction does not yet have a connection. |
| 4395 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4396 | |
| 4397 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4398 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4399 | |
| 4400 | response = trans->GetResponseInfo(); |
| 4401 | ASSERT_TRUE(response); |
| 4402 | ASSERT_TRUE(response->headers); |
| 4403 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4404 | EXPECT_EQ(200, response->headers->response_code()); |
| 4405 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4406 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4407 | |
| 4408 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4409 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4410 | |
| 4411 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4412 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4413 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4414 | |
| 4415 | trans.reset(); |
| 4416 | session->CloseAllConnections(); |
| 4417 | } |
| 4418 | |
| 4419 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4420 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4421 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4422 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4423 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4424 | HttpRequestInfo request; |
| 4425 | request.method = "GET"; |
| 4426 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4427 | request.traffic_annotation = |
| 4428 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4429 | |
| 4430 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4431 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4432 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4433 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4434 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4435 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4436 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4437 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4438 | mock_handler->set_allows_default_credentials(true); |
| 4439 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4440 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4441 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4442 | |
| 4443 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4444 | NetLog net_log; |
| 4445 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4446 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4447 | |
| 4448 | // Should try to establish tunnel. |
| 4449 | MockWrite data_writes1[] = { |
| 4450 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4451 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4452 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4453 | |
| 4454 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4455 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4456 | "Proxy-Connection: keep-alive\r\n" |
| 4457 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4458 | }; |
| 4459 | |
| 4460 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4461 | // second request is sent. |
| 4462 | MockRead data_reads1[] = { |
| 4463 | // No credentials. |
| 4464 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4465 | MockRead("Content-Length: 0\r\n"), |
| 4466 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4467 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4468 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4469 | }; |
| 4470 | |
| 4471 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4472 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4473 | // request. |
| 4474 | MockWrite data_writes2[] = { |
| 4475 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4476 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4477 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4478 | }; |
| 4479 | |
| 4480 | // The proxy, having had more than enough of us, just hangs up. |
| 4481 | MockRead data_reads2[] = { |
| 4482 | // No credentials. |
| 4483 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4484 | }; |
| 4485 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4486 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4487 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4488 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4489 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4490 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4491 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4492 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4493 | |
| 4494 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4495 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4496 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4497 | |
| 4498 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4499 | ASSERT_TRUE(response); |
| 4500 | ASSERT_TRUE(response->headers); |
| 4501 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4502 | EXPECT_EQ(407, response->headers->response_code()); |
| 4503 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4504 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4505 | EXPECT_FALSE(response->auth_challenge); |
| 4506 | |
| 4507 | LoadTimingInfo load_timing_info; |
| 4508 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4509 | |
| 4510 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4511 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4512 | |
| 4513 | trans.reset(); |
| 4514 | session->CloseAllConnections(); |
| 4515 | } |
| 4516 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4517 | // This test exercises an odd edge case where the proxy closes the connection |
| 4518 | // after the authentication handshake is complete. Presumably this technique is |
| 4519 | // used in lieu of returning a 403 or 5xx status code when the authentication |
| 4520 | // succeeds, but the user is not authorized to connect to the destination |
| 4521 | // server. There's no standard for what a proxy should do to indicate a blocked |
| 4522 | // site. |
| 4523 | TEST_F(HttpNetworkTransactionTest, |
| 4524 | AuthAllowsDefaultCredentialsTunnelConnectionClosesBeforeBody) { |
| 4525 | HttpRequestInfo request; |
| 4526 | request.method = "GET"; |
| 4527 | request.url = GURL("https://www.example.org/"); |
| 4528 | request.traffic_annotation = |
| 4529 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4530 | |
| 4531 | // Configure against proxy server "myproxy:70". |
| 4532 | session_deps_.proxy_resolution_service = |
| 4533 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4534 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4535 | |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 4536 | // When TLS 1.3 is enabled, spurious connections are made as part of the SSL |
| 4537 | // version interference probes. |
| 4538 | // TODO(crbug.com/906668): Correctly handle version interference probes to |
| 4539 | // test TLS 1.3. |
| 4540 | SSLConfig config; |
| 4541 | config.version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
| 4542 | session_deps_.ssl_config_service = |
| 4543 | std::make_unique<TestSSLConfigService>(config); |
| 4544 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4545 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
| 4546 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4547 | |
| 4548 | // Create two mock AuthHandlers. This is because the transaction gets retried |
| 4549 | // after the first ERR_CONNECTION_CLOSED since it's ambiguous whether there |
| 4550 | // was a real network error. |
| 4551 | // |
| 4552 | // The handlers support both default and explicit credentials. The retry |
| 4553 | // mentioned above should be able to reuse the default identity. Thus there |
| 4554 | // should never be a need to prompt for explicit credentials. |
| 4555 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4556 | mock_handler->set_allows_default_credentials(true); |
| 4557 | mock_handler->set_allows_explicit_credentials(true); |
| 4558 | mock_handler->set_connection_based(true); |
| 4559 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4560 | HttpAuth::AUTH_PROXY); |
| 4561 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4562 | mock_handler->set_allows_default_credentials(true); |
| 4563 | mock_handler->set_allows_explicit_credentials(true); |
| 4564 | mock_handler->set_connection_based(true); |
| 4565 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4566 | HttpAuth::AUTH_PROXY); |
| 4567 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4568 | |
| 4569 | NetLog net_log; |
| 4570 | session_deps_.net_log = &net_log; |
| 4571 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4572 | |
| 4573 | // Data for both sockets. |
| 4574 | // |
| 4575 | // Writes are for the tunnel establishment attempts and the |
| 4576 | // authentication handshake. |
| 4577 | MockWrite data_writes1[] = { |
| 4578 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4579 | "Host: www.example.org:443\r\n" |
| 4580 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4581 | |
| 4582 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4583 | "Host: www.example.org:443\r\n" |
| 4584 | "Proxy-Connection: keep-alive\r\n" |
| 4585 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4586 | |
| 4587 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4588 | "Host: www.example.org:443\r\n" |
| 4589 | "Proxy-Connection: keep-alive\r\n" |
| 4590 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4591 | }; |
| 4592 | |
| 4593 | // The server side of the authentication handshake. Note that the response to |
| 4594 | // the final CONNECT request is ERR_CONNECTION_CLOSED. |
| 4595 | MockRead data_reads1[] = { |
| 4596 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4597 | MockRead("Content-Length: 0\r\n"), |
| 4598 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4599 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4600 | |
| 4601 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4602 | MockRead("Content-Length: 0\r\n"), |
| 4603 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4604 | MockRead("Proxy-Authenticate: Mock foo\r\n\r\n"), |
| 4605 | |
| 4606 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4607 | }; |
| 4608 | |
| 4609 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 4610 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4611 | |
| 4612 | // The second socket is for the reconnection attempt. Data is identical to the |
| 4613 | // first attempt. |
| 4614 | StaticSocketDataProvider data2(data_reads1, data_writes1); |
| 4615 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4616 | |
| 4617 | auto trans = |
| 4618 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4619 | |
| 4620 | TestCompletionCallback callback; |
| 4621 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4622 | |
| 4623 | // Two rounds per handshake. After one retry, the error is propagated up the |
| 4624 | // stack. |
| 4625 | for (int i = 0; i < 4; ++i) { |
| 4626 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4627 | |
| 4628 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4629 | ASSERT_TRUE(response); |
| 4630 | ASSERT_TRUE(response->headers); |
| 4631 | EXPECT_EQ(407, response->headers->response_code()); |
| 4632 | ASSERT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4633 | |
| 4634 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4635 | } |
| 4636 | |
| 4637 | // One shall be the number thou shalt retry, and the number of the retrying |
| 4638 | // shall be one. Two shalt thou not retry, neither retry thou zero, excepting |
| 4639 | // that thou then proceed to one. Three is right out. Once the number one, |
| 4640 | // being the first number, be reached, then lobbest thou thy |
| 4641 | // ERR_CONNECTION_CLOSED towards they network transaction, who shall snuff it. |
| 4642 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.GetResult(rv)); |
| 4643 | |
| 4644 | trans.reset(); |
| 4645 | session->CloseAllConnections(); |
| 4646 | } |
| 4647 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4648 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4649 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4650 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4651 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4652 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4653 | HttpRequestInfo request; |
| 4654 | request.method = "GET"; |
| 4655 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4656 | request.traffic_annotation = |
| 4657 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4658 | |
| 4659 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4660 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4661 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4662 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4663 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4664 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4665 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4666 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4667 | mock_handler->set_allows_default_credentials(true); |
| 4668 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4669 | HttpAuth::AUTH_PROXY); |
| 4670 | // Add another handler for the second challenge. It supports default |
| 4671 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4672 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4673 | mock_handler->set_allows_default_credentials(true); |
| 4674 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4675 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4676 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4677 | |
| 4678 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4679 | NetLog net_log; |
| 4680 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4681 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4682 | |
| 4683 | // Should try to establish tunnel. |
| 4684 | MockWrite data_writes1[] = { |
| 4685 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4686 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4687 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4688 | }; |
| 4689 | |
| 4690 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4691 | // connection. |
| 4692 | MockRead data_reads1[] = { |
| 4693 | // No credentials. |
| 4694 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4695 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4696 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4697 | }; |
| 4698 | |
| 4699 | // Since the first connection was closed, need to establish another once given |
| 4700 | // credentials. |
| 4701 | MockWrite data_writes2[] = { |
| 4702 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4703 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4704 | "Proxy-Connection: keep-alive\r\n" |
| 4705 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4706 | }; |
| 4707 | |
| 4708 | MockRead data_reads2[] = { |
| 4709 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4710 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4711 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4712 | }; |
| 4713 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4714 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4715 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4716 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4717 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4718 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4719 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4720 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4721 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4722 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4723 | |
| 4724 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4725 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4726 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4727 | |
| 4728 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4729 | ASSERT_TRUE(response); |
| 4730 | ASSERT_TRUE(response->headers); |
| 4731 | EXPECT_EQ(407, response->headers->response_code()); |
| 4732 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4733 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4734 | EXPECT_FALSE(response->auth_challenge); |
| 4735 | |
| 4736 | LoadTimingInfo load_timing_info; |
| 4737 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4738 | |
| 4739 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4740 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4741 | response = trans->GetResponseInfo(); |
| 4742 | ASSERT_TRUE(response); |
| 4743 | ASSERT_TRUE(response->headers); |
| 4744 | EXPECT_EQ(407, response->headers->response_code()); |
| 4745 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4746 | EXPECT_TRUE(response->auth_challenge); |
| 4747 | |
| 4748 | trans.reset(); |
| 4749 | session->CloseAllConnections(); |
| 4750 | } |
| 4751 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4752 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4753 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4754 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4755 | // authentication handshake can continue with the same scheme but with a |
| 4756 | // different identity. |
| 4757 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4758 | HttpRequestInfo request; |
| 4759 | request.method = "GET"; |
| 4760 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4761 | request.traffic_annotation = |
| 4762 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4763 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4764 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4765 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4766 | |
| 4767 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4768 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4769 | mock_handler->set_allows_default_credentials(true); |
| 4770 | mock_handler->set_allows_explicit_credentials(true); |
| 4771 | mock_handler->set_connection_based(true); |
| 4772 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4773 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4774 | HttpAuth::AUTH_SERVER); |
| 4775 | |
| 4776 | // Add another handler for the second challenge. It supports default |
| 4777 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4778 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4779 | mock_handler->set_allows_default_credentials(true); |
| 4780 | mock_handler->set_allows_explicit_credentials(true); |
| 4781 | mock_handler->set_connection_based(true); |
| 4782 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4783 | HttpAuth::AUTH_SERVER); |
| 4784 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4785 | |
| 4786 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4787 | |
| 4788 | MockWrite data_writes1[] = { |
| 4789 | MockWrite("GET / HTTP/1.1\r\n" |
| 4790 | "Host: www.example.org\r\n" |
| 4791 | "Connection: keep-alive\r\n\r\n"), |
| 4792 | }; |
| 4793 | |
| 4794 | MockRead data_reads1[] = { |
| 4795 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4796 | "WWW-Authenticate: Mock\r\n" |
| 4797 | "Connection: keep-alive\r\n\r\n"), |
| 4798 | }; |
| 4799 | |
| 4800 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4801 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4802 | // transaction procceds without an authorization header. |
| 4803 | MockWrite data_writes2[] = { |
| 4804 | MockWrite("GET / HTTP/1.1\r\n" |
| 4805 | "Host: www.example.org\r\n" |
| 4806 | "Connection: keep-alive\r\n\r\n"), |
| 4807 | }; |
| 4808 | |
| 4809 | MockRead data_reads2[] = { |
| 4810 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4811 | "WWW-Authenticate: Mock\r\n" |
| 4812 | "Connection: keep-alive\r\n\r\n"), |
| 4813 | }; |
| 4814 | |
| 4815 | MockWrite data_writes3[] = { |
| 4816 | MockWrite("GET / HTTP/1.1\r\n" |
| 4817 | "Host: www.example.org\r\n" |
| 4818 | "Connection: keep-alive\r\n" |
| 4819 | "Authorization: auth_token\r\n\r\n"), |
| 4820 | }; |
| 4821 | |
| 4822 | MockRead data_reads3[] = { |
| 4823 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4824 | "Content-Length: 5\r\n" |
| 4825 | "Content-Type: text/plain\r\n" |
| 4826 | "Connection: keep-alive\r\n\r\n" |
| 4827 | "Hello"), |
| 4828 | }; |
| 4829 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4830 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4831 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4832 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4833 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4834 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4835 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4836 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4837 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4838 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4839 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4840 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4841 | |
| 4842 | TestCompletionCallback callback; |
| 4843 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4844 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4845 | |
| 4846 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4847 | ASSERT_TRUE(response); |
| 4848 | ASSERT_TRUE(response->headers); |
| 4849 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4850 | |
| 4851 | // The following three tests assert that an authentication challenge was |
| 4852 | // received and that the stack is ready to respond to the challenge using |
| 4853 | // ambient credentials. |
| 4854 | EXPECT_EQ(401, response->headers->response_code()); |
| 4855 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4856 | EXPECT_FALSE(response->auth_challenge); |
| 4857 | |
| 4858 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4859 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4860 | response = trans->GetResponseInfo(); |
| 4861 | ASSERT_TRUE(response); |
| 4862 | ASSERT_TRUE(response->headers); |
| 4863 | |
| 4864 | // The following three tests assert that an authentication challenge was |
| 4865 | // received and that the stack needs explicit credentials before it is ready |
| 4866 | // to respond to the challenge. |
| 4867 | EXPECT_EQ(401, response->headers->response_code()); |
| 4868 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4869 | EXPECT_TRUE(response->auth_challenge); |
| 4870 | |
| 4871 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4872 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4873 | response = trans->GetResponseInfo(); |
| 4874 | ASSERT_TRUE(response); |
| 4875 | ASSERT_TRUE(response->headers); |
| 4876 | EXPECT_EQ(200, response->headers->response_code()); |
| 4877 | |
| 4878 | trans.reset(); |
| 4879 | session->CloseAllConnections(); |
| 4880 | } |
| 4881 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4882 | // Proxy resolver that returns a proxy with the same host and port for different |
| 4883 | // schemes, based on the path of the URL being requests. |
| 4884 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 4885 | public: |
| 4886 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 4887 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 4888 | |
| 4889 | static std::string ProxyHostPortPairAsString() { return "proxy.test:10000"; } |
| 4890 | |
| 4891 | static HostPortPair ProxyHostPortPair() { |
| 4892 | return HostPortPair::FromString(ProxyHostPortPairAsString()); |
| 4893 | } |
| 4894 | |
| 4895 | // ProxyResolver implementation. |
| 4896 | int GetProxyForURL(const GURL& url, |
| 4897 | ProxyInfo* results, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4898 | CompletionOnceCallback callback, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4899 | std::unique_ptr<Request>* request, |
| 4900 | const NetLogWithSource& /*net_log*/) override { |
| 4901 | *results = ProxyInfo(); |
Ramin Halavati | 921731ea | 2018-03-16 08:24:57 | [diff] [blame] | 4902 | results->set_traffic_annotation( |
| 4903 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4904 | if (url.path() == "/socks4") { |
| 4905 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 4906 | return OK; |
| 4907 | } |
| 4908 | if (url.path() == "/socks5") { |
| 4909 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 4910 | return OK; |
| 4911 | } |
| 4912 | if (url.path() == "/http") { |
| 4913 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 4914 | return OK; |
| 4915 | } |
| 4916 | if (url.path() == "/https") { |
| 4917 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 4918 | return OK; |
| 4919 | } |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 4920 | if (url.path() == "/https_trusted") { |
| 4921 | results->UseProxyServer(ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 4922 | ProxyHostPortPair(), |
| 4923 | true /* is_trusted_proxy */)); |
| 4924 | return OK; |
| 4925 | } |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4926 | NOTREACHED(); |
| 4927 | return ERR_NOT_IMPLEMENTED; |
| 4928 | } |
| 4929 | |
| 4930 | private: |
| 4931 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 4932 | }; |
| 4933 | |
| 4934 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 4935 | : public ProxyResolverFactory { |
| 4936 | public: |
| 4937 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 4938 | : ProxyResolverFactory(false) {} |
| 4939 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4940 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 4941 | std::unique_ptr<ProxyResolver>* resolver, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4942 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4943 | std::unique_ptr<Request>* request) override { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4944 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 4945 | return OK; |
| 4946 | } |
| 4947 | |
| 4948 | private: |
| 4949 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 4950 | }; |
| 4951 | |
| 4952 | // 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] | 4953 | // same address, the connections are not grouped together. i.e., a request to |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4954 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 4955 | // request to foo.com using proxy.com as an HTTP proxy. |
| 4956 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4957 | session_deps_.proxy_resolution_service = |
| 4958 | std::make_unique<ProxyResolutionService>( |
| 4959 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 4960 | ProxyConfig::CreateAutoDetect(), TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 4961 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
| 4962 | nullptr); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4963 | |
| 4964 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4965 | |
| 4966 | MockWrite socks_writes[] = { |
| 4967 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 4968 | kSOCKS4OkRequestLocalHostPort80Length), |
| 4969 | MockWrite(SYNCHRONOUS, |
| 4970 | "GET /socks4 HTTP/1.1\r\n" |
| 4971 | "Host: test\r\n" |
| 4972 | "Connection: keep-alive\r\n\r\n"), |
| 4973 | }; |
| 4974 | MockRead socks_reads[] = { |
| 4975 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 4976 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4977 | "Connection: keep-alive\r\n" |
| 4978 | "Content-Length: 15\r\n\r\n" |
| 4979 | "SOCKS4 Response"), |
| 4980 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4981 | StaticSocketDataProvider socks_data(socks_reads, socks_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4982 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 4983 | |
| 4984 | const char kSOCKS5Request[] = { |
| 4985 | 0x05, // Version |
| 4986 | 0x01, // Command (CONNECT) |
| 4987 | 0x00, // Reserved |
| 4988 | 0x03, // Address type (DOMAINNAME) |
| 4989 | 0x04, // Length of domain (4) |
| 4990 | 't', 'e', 's', 't', // Domain string |
| 4991 | 0x00, 0x50, // 16-bit port (80) |
| 4992 | }; |
| 4993 | MockWrite socks5_writes[] = { |
| 4994 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 4995 | MockWrite(ASYNC, kSOCKS5Request, base::size(kSOCKS5Request)), |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4996 | MockWrite(SYNCHRONOUS, |
| 4997 | "GET /socks5 HTTP/1.1\r\n" |
| 4998 | "Host: test\r\n" |
| 4999 | "Connection: keep-alive\r\n\r\n"), |
| 5000 | }; |
| 5001 | MockRead socks5_reads[] = { |
| 5002 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 5003 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 5004 | MockRead("HTTP/1.0 200 OK\r\n" |
| 5005 | "Connection: keep-alive\r\n" |
| 5006 | "Content-Length: 15\r\n\r\n" |
| 5007 | "SOCKS5 Response"), |
| 5008 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5009 | StaticSocketDataProvider socks5_data(socks5_reads, socks5_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5010 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 5011 | |
| 5012 | MockWrite http_writes[] = { |
| 5013 | MockWrite(SYNCHRONOUS, |
| 5014 | "GET http://test/http HTTP/1.1\r\n" |
| 5015 | "Host: test\r\n" |
| 5016 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5017 | }; |
| 5018 | MockRead http_reads[] = { |
| 5019 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5020 | "Proxy-Connection: keep-alive\r\n" |
| 5021 | "Content-Length: 13\r\n\r\n" |
| 5022 | "HTTP Response"), |
| 5023 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5024 | StaticSocketDataProvider http_data(http_reads, http_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5025 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 5026 | |
| 5027 | MockWrite https_writes[] = { |
| 5028 | MockWrite(SYNCHRONOUS, |
| 5029 | "GET http://test/https HTTP/1.1\r\n" |
| 5030 | "Host: test\r\n" |
| 5031 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5032 | }; |
| 5033 | MockRead https_reads[] = { |
| 5034 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5035 | "Proxy-Connection: keep-alive\r\n" |
| 5036 | "Content-Length: 14\r\n\r\n" |
| 5037 | "HTTPS Response"), |
| 5038 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5039 | StaticSocketDataProvider https_data(https_reads, https_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5040 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 5041 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 5042 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5043 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5044 | MockWrite https_trusted_writes[] = { |
| 5045 | MockWrite(SYNCHRONOUS, |
| 5046 | "GET http://test/https_trusted HTTP/1.1\r\n" |
| 5047 | "Host: test\r\n" |
| 5048 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5049 | }; |
| 5050 | MockRead https_trusted_reads[] = { |
| 5051 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5052 | "Proxy-Connection: keep-alive\r\n" |
| 5053 | "Content-Length: 22\r\n\r\n" |
| 5054 | "HTTPS Trusted Response"), |
| 5055 | }; |
| 5056 | StaticSocketDataProvider trusted_https_data(https_trusted_reads, |
| 5057 | https_trusted_writes); |
| 5058 | session_deps_.socket_factory->AddSocketDataProvider(&trusted_https_data); |
| 5059 | SSLSocketDataProvider ssl2(SYNCHRONOUS, OK); |
| 5060 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 5061 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5062 | struct TestCase { |
| 5063 | GURL url; |
| 5064 | std::string expected_response; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5065 | // 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] | 5066 | // after the test. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5067 | int expected_idle_socks4_sockets; |
| 5068 | int expected_idle_socks5_sockets; |
| 5069 | // How many idle sockets there should be in the HTTP/HTTPS proxy socket |
| 5070 | // pools after the test. |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5071 | int expected_idle_http_sockets; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5072 | int expected_idle_https_sockets; |
| 5073 | // How many idle sockets there should be in the HTTPS proxy socket pool with |
| 5074 | // the ProxyServer's |is_trusted_proxy| bit set after the test. |
| 5075 | int expected_idle_trusted_https_sockets; |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5076 | } const kTestCases[] = { |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5077 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0, 0, 0, 0}, |
| 5078 | {GURL("http://test/socks5"), "SOCKS5 Response", 1, 1, 0, 0, 0}, |
| 5079 | {GURL("http://test/http"), "HTTP Response", 1, 1, 1, 0, 0}, |
| 5080 | {GURL("http://test/https"), "HTTPS Response", 1, 1, 1, 1, 0}, |
| 5081 | {GURL("http://test/https_trusted"), "HTTPS Trusted Response", 1, 1, 1, 1, |
| 5082 | 1}, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5083 | }; |
| 5084 | |
| 5085 | for (const auto& test_case : kTestCases) { |
| 5086 | HttpRequestInfo request; |
| 5087 | request.method = "GET"; |
| 5088 | request.url = test_case.url; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5089 | request.traffic_annotation = |
| 5090 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5091 | std::unique_ptr<HttpNetworkTransaction> trans = |
| 5092 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 5093 | session.get()); |
| 5094 | TestCompletionCallback callback; |
| 5095 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 5096 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5097 | |
| 5098 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5099 | ASSERT_TRUE(response); |
| 5100 | ASSERT_TRUE(response->headers); |
| 5101 | EXPECT_EQ(200, response->headers->response_code()); |
| 5102 | std::string response_data; |
| 5103 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 5104 | EXPECT_EQ(test_case.expected_response, response_data); |
| 5105 | |
| 5106 | // Return the socket to the socket pool, so can make sure it's not used for |
| 5107 | // the next requests. |
| 5108 | trans.reset(); |
| 5109 | base::RunLoop().RunUntilIdle(); |
| 5110 | |
| 5111 | // Check the number of idle sockets in the pool, to make sure that used |
| 5112 | // sockets are indeed being returned to the socket pool. If each request |
| 5113 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 5114 | // pass. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5115 | EXPECT_EQ(test_case.expected_idle_socks4_sockets, |
| 5116 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5117 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5118 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5119 | ProxyServer(ProxyServer::SCHEME_SOCKS4, |
| 5120 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5121 | ProxyHostPortPair())) |
| 5122 | ->IdleSocketCount()); |
| 5123 | EXPECT_EQ(test_case.expected_idle_socks5_sockets, |
| 5124 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5125 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5126 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5127 | ProxyServer(ProxyServer::SCHEME_SOCKS5, |
| 5128 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5129 | ProxyHostPortPair())) |
| 5130 | ->IdleSocketCount()); |
| 5131 | EXPECT_EQ(test_case.expected_idle_http_sockets, |
| 5132 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5133 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5134 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5135 | ProxyServer(ProxyServer::SCHEME_HTTP, |
| 5136 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5137 | ProxyHostPortPair())) |
| 5138 | ->IdleSocketCount()); |
| 5139 | EXPECT_EQ(test_case.expected_idle_https_sockets, |
| 5140 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5141 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5142 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5143 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5144 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5145 | ProxyHostPortPair())) |
| 5146 | ->IdleSocketCount()); |
| 5147 | EXPECT_EQ(test_case.expected_idle_trusted_https_sockets, |
| 5148 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5149 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5150 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5151 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5152 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5153 | ProxyHostPortPair(), |
| 5154 | true /* is_trusted_proxy */)) |
| 5155 | ->IdleSocketCount()); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5156 | } |
| 5157 | } |
| 5158 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5159 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5160 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5161 | HttpRequestInfo request1; |
| 5162 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5163 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5164 | request1.traffic_annotation = |
| 5165 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5166 | |
| 5167 | HttpRequestInfo request2; |
| 5168 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5169 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5170 | request2.traffic_annotation = |
| 5171 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5172 | |
| 5173 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5174 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5175 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5176 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5177 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5178 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5179 | |
| 5180 | // Since we have proxy, should try to establish tunnel. |
| 5181 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5182 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5183 | "Host: www.example.org:443\r\n" |
| 5184 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5185 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5186 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5187 | "Host: www.example.org\r\n" |
| 5188 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5189 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5190 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5191 | "Host: www.example.org\r\n" |
| 5192 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5193 | }; |
| 5194 | |
| 5195 | // The proxy responds to the connect with a 407, using a persistent |
| 5196 | // connection. |
| 5197 | MockRead data_reads1[] = { |
| 5198 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5199 | |
| 5200 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5201 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5202 | MockRead(SYNCHRONOUS, "1"), |
| 5203 | |
| 5204 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5205 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5206 | MockRead(SYNCHRONOUS, "22"), |
| 5207 | }; |
| 5208 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5209 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5210 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5211 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5212 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5213 | |
| 5214 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5215 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5216 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5217 | |
| 5218 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5219 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5220 | |
| 5221 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5222 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5223 | |
| 5224 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5225 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5226 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5227 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5228 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5229 | |
| 5230 | LoadTimingInfo load_timing_info1; |
| 5231 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5232 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5233 | |
| 5234 | trans1.reset(); |
| 5235 | |
| 5236 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5237 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5238 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5239 | |
| 5240 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5241 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5242 | |
| 5243 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5244 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5245 | |
| 5246 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5247 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5248 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5249 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5250 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5251 | |
| 5252 | LoadTimingInfo load_timing_info2; |
| 5253 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5254 | TestLoadTimingReused(load_timing_info2); |
| 5255 | |
| 5256 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5257 | |
| 5258 | trans2.reset(); |
| 5259 | session->CloseAllConnections(); |
| 5260 | } |
| 5261 | |
| 5262 | // 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] | 5263 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5264 | HttpRequestInfo request1; |
| 5265 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5266 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5267 | request1.traffic_annotation = |
| 5268 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5269 | |
| 5270 | HttpRequestInfo request2; |
| 5271 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5272 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5273 | request2.traffic_annotation = |
| 5274 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5275 | |
| 5276 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5277 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5278 | ProxyResolutionService::CreateFixedFromPacResult( |
| 5279 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5280 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5281 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5282 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5283 | |
| 5284 | // Since we have proxy, should try to establish tunnel. |
| 5285 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5286 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5287 | "Host: www.example.org:443\r\n" |
| 5288 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5289 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5290 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5291 | "Host: www.example.org\r\n" |
| 5292 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5293 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5294 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5295 | "Host: www.example.org\r\n" |
| 5296 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5297 | }; |
| 5298 | |
| 5299 | // The proxy responds to the connect with a 407, using a persistent |
| 5300 | // connection. |
| 5301 | MockRead data_reads1[] = { |
| 5302 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5303 | |
| 5304 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5305 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5306 | MockRead(SYNCHRONOUS, "1"), |
| 5307 | |
| 5308 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5309 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5310 | MockRead(SYNCHRONOUS, "22"), |
| 5311 | }; |
| 5312 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5313 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5314 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5315 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5316 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5317 | |
| 5318 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5319 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5320 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5321 | |
| 5322 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5323 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5324 | |
| 5325 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5326 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5327 | |
| 5328 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5329 | ASSERT_TRUE(response1); |
| 5330 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5331 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5332 | |
| 5333 | LoadTimingInfo load_timing_info1; |
| 5334 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5335 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 5336 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 5337 | |
| 5338 | trans1.reset(); |
| 5339 | |
| 5340 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5341 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5342 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5343 | |
| 5344 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5345 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5346 | |
| 5347 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5348 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5349 | |
| 5350 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5351 | ASSERT_TRUE(response2); |
| 5352 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5353 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5354 | |
| 5355 | LoadTimingInfo load_timing_info2; |
| 5356 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5357 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 5358 | |
| 5359 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5360 | |
| 5361 | trans2.reset(); |
| 5362 | session->CloseAllConnections(); |
| 5363 | } |
| 5364 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5365 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5366 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5367 | HttpRequestInfo request; |
| 5368 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5369 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5370 | request.traffic_annotation = |
| 5371 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5372 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5373 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5374 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5375 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5376 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5377 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5378 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5379 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5380 | // Since we have proxy, should use full url |
| 5381 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5382 | MockWrite( |
| 5383 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5384 | "Host: www.example.org\r\n" |
| 5385 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5386 | }; |
| 5387 | |
| 5388 | MockRead data_reads1[] = { |
| 5389 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5390 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5391 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5392 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5393 | }; |
| 5394 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5395 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5396 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5397 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5398 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5399 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5400 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5401 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5402 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5403 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5404 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5405 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5406 | |
| 5407 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5408 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5409 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5410 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5411 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5412 | TestLoadTimingNotReused(load_timing_info, |
| 5413 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5414 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5415 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5416 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5417 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5418 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5419 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5420 | EXPECT_EQ(200, response->headers->response_code()); |
| 5421 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5422 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5423 | |
| 5424 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5425 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5426 | } |
| 5427 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5428 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5429 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5430 | HttpRequestInfo request; |
| 5431 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5432 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5433 | request.traffic_annotation = |
| 5434 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5435 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5436 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5437 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5438 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5439 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5440 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5441 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5442 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5443 | // fetch http://www.example.org/ via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5444 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5445 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5446 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5447 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5448 | spdy::SpdySerializedFrame resp( |
| 5449 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 5450 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5451 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5452 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5453 | }; |
| 5454 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5455 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5456 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5457 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5458 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5459 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5460 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5461 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5462 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5463 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5464 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5465 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5466 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5467 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5468 | |
| 5469 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5470 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5471 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5472 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5473 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5474 | TestLoadTimingNotReused(load_timing_info, |
| 5475 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5476 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5477 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5478 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5479 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5480 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5481 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5482 | |
| 5483 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5484 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5485 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5486 | } |
| 5487 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5488 | // Verifies that a session which races and wins against the owning transaction |
| 5489 | // (completing prior to host resolution), doesn't fail the transaction. |
| 5490 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5491 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5492 | HttpRequestInfo request; |
| 5493 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5494 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5495 | request.traffic_annotation = |
| 5496 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5497 | |
| 5498 | // Configure SPDY proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5499 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5500 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5501 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5502 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5503 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5504 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5505 | // Fetch http://www.example.org/ through the SPDY proxy. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5506 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5507 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5508 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5509 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5510 | spdy::SpdySerializedFrame resp( |
| 5511 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5512 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5513 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5514 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5515 | }; |
| 5516 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5517 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5518 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5519 | |
| 5520 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5521 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5522 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5523 | |
| 5524 | TestCompletionCallback callback1; |
| 5525 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5526 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5527 | |
| 5528 | // Stall the hostname resolution begun by the transaction. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5529 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5530 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5531 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5532 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5533 | |
| 5534 | // Race a session to the proxy, which completes first. |
| 5535 | session_deps_.host_resolver->set_ondemand_mode(false); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 5536 | SpdySessionKey key(HostPortPair("proxy", 70), ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 5537 | PRIVACY_MODE_DISABLED, |
| 5538 | SpdySessionKey::IsProxySession::kTrue, SocketTag()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5539 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 5540 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5541 | |
| 5542 | // Unstall the resolution begun by the transaction. |
| 5543 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5544 | session_deps_.host_resolver->ResolveAllPending(); |
| 5545 | |
| 5546 | EXPECT_FALSE(callback1.have_result()); |
| 5547 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5548 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5549 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5550 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5551 | ASSERT_TRUE(response); |
| 5552 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5553 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5554 | |
| 5555 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5556 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5557 | EXPECT_EQ(kUploadData, response_data); |
| 5558 | } |
| 5559 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5560 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5561 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5562 | HttpRequestInfo request; |
| 5563 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5564 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5565 | request.traffic_annotation = |
| 5566 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5567 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5568 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5569 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5570 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5571 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5572 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5573 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5574 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5575 | // The first request will be a bare GET, the second request will be a |
| 5576 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5577 | spdy_util_.set_default_url(request.url); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5578 | spdy::SpdySerializedFrame req_get( |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5579 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5580 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5581 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5582 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5583 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5584 | spdy::SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5585 | kExtraAuthorizationHeaders, base::size(kExtraAuthorizationHeaders) / 2, 3, |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5586 | LOWEST)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5587 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5588 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5589 | }; |
| 5590 | |
| 5591 | // The first response is a 407 proxy authentication challenge, and the second |
| 5592 | // response will be a 200 response since the second request includes a valid |
| 5593 | // Authorization header. |
| 5594 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5595 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5596 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5597 | spdy::SpdySerializedFrame resp_authentication( |
| 5598 | spdy_util_.ConstructSpdyReplyError( |
| 5599 | "407", kExtraAuthenticationHeaders, |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5600 | base::size(kExtraAuthenticationHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5601 | spdy::SpdySerializedFrame body_authentication( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5602 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5603 | spdy::SpdySerializedFrame resp_data( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5604 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5605 | spdy::SpdySerializedFrame body_data( |
| 5606 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5607 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5608 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5609 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5610 | CreateMockRead(resp_data, 4), |
| 5611 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5612 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5613 | }; |
| 5614 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5615 | SequencedSocketData data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5616 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5617 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5618 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5619 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5620 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5621 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5622 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5623 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5624 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5625 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5626 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5627 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5628 | |
| 5629 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5630 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5631 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5632 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5633 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5634 | ASSERT_TRUE(response); |
| 5635 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5636 | EXPECT_EQ(407, response->headers->response_code()); |
| 5637 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5638 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5639 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5640 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5641 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5642 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5643 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5644 | |
| 5645 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5646 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5647 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5648 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5649 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5650 | ASSERT_TRUE(response_restart); |
| 5651 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5652 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5653 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5654 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5655 | } |
| 5656 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5657 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5658 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5659 | HttpRequestInfo request; |
| 5660 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5661 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5662 | request.traffic_annotation = |
| 5663 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5664 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5665 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5666 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5667 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5668 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5669 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5670 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5671 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5672 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5673 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5674 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5675 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5676 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5677 | HostPortPair("www.example.org", 443))); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5678 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5679 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5680 | const char get[] = |
| 5681 | "GET / HTTP/1.1\r\n" |
| 5682 | "Host: www.example.org\r\n" |
| 5683 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5684 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5685 | spdy_util_.ConstructSpdyDataFrame(1, get, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5686 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5687 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5688 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 5689 | "Content-Length: 10\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5690 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5691 | spdy_util_.ConstructSpdyDataFrame(1, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5692 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5693 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5694 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5695 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5696 | |
| 5697 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5698 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5699 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5700 | }; |
| 5701 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5702 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5703 | CreateMockRead(conn_resp, 1, ASYNC), |
| 5704 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 5705 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 5706 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5707 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5708 | }; |
| 5709 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5710 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5711 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5712 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5713 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5714 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5715 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5716 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5717 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5718 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5719 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5720 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5721 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5722 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5723 | |
| 5724 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5725 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5726 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5727 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5728 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5729 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5730 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5731 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5732 | ASSERT_TRUE(response); |
| 5733 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5734 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5735 | |
| 5736 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5737 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5738 | EXPECT_EQ("1234567890", response_data); |
| 5739 | } |
| 5740 | |
| 5741 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5742 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5743 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5744 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5745 | HttpRequestInfo request; |
| 5746 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5747 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5748 | request.traffic_annotation = |
| 5749 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5750 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5751 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5752 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5753 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5754 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5755 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5756 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5757 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5758 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5759 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5760 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5761 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5762 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5763 | HostPortPair("www.example.org", 443))); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5764 | // fetch https://www.example.org/ via SPDY |
| 5765 | const char kMyUrl[] = "https://www.example.org/"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5766 | spdy::SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5767 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5768 | spdy::SpdySerializedFrame wrapped_get( |
| 5769 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 5770 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5771 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5772 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5773 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5774 | spdy::SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5775 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5776 | spdy::SpdySerializedFrame body( |
| 5777 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5778 | spdy::SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5779 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5780 | spdy::SpdySerializedFrame window_update_get_resp( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5781 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5782 | spdy::SpdySerializedFrame window_update_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5783 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5784 | |
| 5785 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5786 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5787 | CreateMockWrite(window_update_get_resp, 6), |
| 5788 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5789 | }; |
| 5790 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5791 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5792 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5793 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5794 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5795 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5796 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5797 | }; |
| 5798 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5799 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5800 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5801 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5802 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5803 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5804 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5805 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5806 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5807 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5808 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5809 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5810 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5811 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5812 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5813 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5814 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5815 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5816 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5817 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5818 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5819 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5820 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5821 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5822 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5823 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5824 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5825 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5826 | ASSERT_TRUE(response); |
| 5827 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5828 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5829 | |
| 5830 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5831 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5832 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5833 | } |
| 5834 | |
| 5835 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5836 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5837 | HttpRequestInfo request; |
| 5838 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5839 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5840 | request.traffic_annotation = |
| 5841 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5842 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5843 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5844 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5845 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5846 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5847 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5848 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5849 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5850 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5851 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5852 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5853 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5854 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5855 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5856 | spdy::SpdySerializedFrame get( |
| 5857 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5858 | |
| 5859 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5860 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5861 | }; |
| 5862 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5863 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
| 5864 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5865 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5866 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5867 | }; |
| 5868 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5869 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5870 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5871 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5872 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5873 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5874 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5875 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5876 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5877 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5878 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5879 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5880 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5881 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5882 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5883 | |
| 5884 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5885 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5886 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5887 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5888 | } |
| 5889 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5890 | // Test the case where a proxied H2 session doesn't exist when an auth challenge |
| 5891 | // is observed, but does exist by the time auth credentials are provided. |
| 5892 | // Proxy-Connection: Close is used so that there's a second DNS lookup, which is |
| 5893 | // what causes the existing H2 session to be noticed and reused. |
| 5894 | TEST_F(HttpNetworkTransactionTest, ProxiedH2SessionAppearsDuringAuth) { |
| 5895 | ProxyConfig proxy_config; |
| 5896 | proxy_config.set_auto_detect(true); |
| 5897 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 5898 | |
| 5899 | CapturingProxyResolver capturing_proxy_resolver; |
| 5900 | capturing_proxy_resolver.set_proxy_server( |
| 5901 | ProxyServer(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 70))); |
| 5902 | session_deps_.proxy_resolution_service = |
| 5903 | std::make_unique<ProxyResolutionService>( |
| 5904 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 5905 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 5906 | std::make_unique<CapturingProxyResolverFactory>( |
| 5907 | &capturing_proxy_resolver), |
| 5908 | nullptr); |
| 5909 | |
| 5910 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 5911 | |
| 5912 | const char kMyUrl[] = "https://www.example.org/"; |
| 5913 | spdy::SpdySerializedFrame get(spdy_util_.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 5914 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5915 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5916 | spdy::SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 5917 | |
| 5918 | spdy_util_.UpdateWithStreamDestruction(1); |
| 5919 | spdy::SpdySerializedFrame get2( |
| 5920 | spdy_util_.ConstructSpdyGet(kMyUrl, 3, LOWEST)); |
| 5921 | spdy::SpdySerializedFrame get_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5922 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5923 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
| 5924 | |
| 5925 | MockWrite auth_challenge_writes[] = { |
| 5926 | MockWrite(ASYNC, 0, |
| 5927 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5928 | "Host: www.example.org:443\r\n" |
| 5929 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5930 | }; |
| 5931 | |
| 5932 | MockRead auth_challenge_reads[] = { |
| 5933 | MockRead(ASYNC, 1, |
| 5934 | "HTTP/1.1 407 Authentication Required\r\n" |
| 5935 | "Content-Length: 0\r\n" |
| 5936 | "Proxy-Connection: close\r\n" |
| 5937 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
| 5938 | }; |
| 5939 | |
| 5940 | MockWrite spdy_writes[] = { |
| 5941 | MockWrite(ASYNC, 0, |
| 5942 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5943 | "Host: www.example.org:443\r\n" |
| 5944 | "Proxy-Connection: keep-alive\r\n" |
| 5945 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5946 | CreateMockWrite(get, 2), |
| 5947 | CreateMockWrite(get2, 5), |
| 5948 | }; |
| 5949 | |
| 5950 | MockRead spdy_reads[] = { |
| 5951 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 5952 | CreateMockRead(get_resp, 3, ASYNC), |
| 5953 | CreateMockRead(body, 4, ASYNC), |
| 5954 | CreateMockRead(get_resp2, 6, ASYNC), |
| 5955 | CreateMockRead(body2, 7, ASYNC), |
| 5956 | |
| 5957 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8), |
| 5958 | }; |
| 5959 | |
| 5960 | SequencedSocketData auth_challenge1(auth_challenge_reads, |
| 5961 | auth_challenge_writes); |
| 5962 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge1); |
| 5963 | |
| 5964 | SequencedSocketData auth_challenge2(auth_challenge_reads, |
| 5965 | auth_challenge_writes); |
| 5966 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge2); |
| 5967 | |
| 5968 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
| 5969 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5970 | |
| 5971 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5972 | ssl.next_proto = kProtoHTTP2; |
| 5973 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5974 | |
| 5975 | TestCompletionCallback callback; |
| 5976 | std::string response_data; |
| 5977 | |
| 5978 | // Run first request until an auth challenge is observed. |
| 5979 | HttpRequestInfo request1; |
| 5980 | request1.method = "GET"; |
| 5981 | request1.url = GURL(kMyUrl); |
| 5982 | request1.traffic_annotation = |
| 5983 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5984 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 5985 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 5986 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5987 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 5988 | ASSERT_TRUE(response); |
| 5989 | ASSERT_TRUE(response->headers); |
| 5990 | EXPECT_EQ(407, response->headers->response_code()); |
| 5991 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5992 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 5993 | |
| 5994 | // Run second request until an auth challenge is observed. |
| 5995 | HttpRequestInfo request2; |
| 5996 | request2.method = "GET"; |
| 5997 | request2.url = GURL(kMyUrl); |
| 5998 | request2.traffic_annotation = |
| 5999 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6000 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6001 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 6002 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6003 | response = trans2.GetResponseInfo(); |
| 6004 | ASSERT_TRUE(response); |
| 6005 | ASSERT_TRUE(response->headers); |
| 6006 | EXPECT_EQ(407, response->headers->response_code()); |
| 6007 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6008 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 6009 | |
| 6010 | // Now provide credentials for the first request, and wait for it to complete. |
| 6011 | rv = trans1.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6012 | rv = callback.GetResult(rv); |
| 6013 | EXPECT_THAT(rv, IsOk()); |
| 6014 | response = trans1.GetResponseInfo(); |
| 6015 | ASSERT_TRUE(response); |
| 6016 | ASSERT_TRUE(response->headers); |
| 6017 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6018 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6019 | EXPECT_EQ(kUploadData, response_data); |
| 6020 | |
| 6021 | // Now provide credentials for the second request. It should notice the |
| 6022 | // existing session, and reuse it. |
| 6023 | rv = trans2.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6024 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6025 | response = trans2.GetResponseInfo(); |
| 6026 | ASSERT_TRUE(response); |
| 6027 | ASSERT_TRUE(response->headers); |
| 6028 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6029 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6030 | EXPECT_EQ(kUploadData, response_data); |
| 6031 | } |
| 6032 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6033 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6034 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6035 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6036 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 6037 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6038 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6039 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6040 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6041 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6042 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6043 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6044 | |
| 6045 | HttpRequestInfo request1; |
| 6046 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6047 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6048 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6049 | request1.traffic_annotation = |
| 6050 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6051 | |
| 6052 | HttpRequestInfo request2; |
| 6053 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6054 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6055 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6056 | request2.traffic_annotation = |
| 6057 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6058 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6059 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6060 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6061 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6062 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6063 | spdy::SpdySerializedFrame conn_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6064 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6065 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6066 | // Fetch https://www.example.org/ via HTTP. |
| 6067 | const char get1[] = |
| 6068 | "GET / HTTP/1.1\r\n" |
| 6069 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6070 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6071 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6072 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6073 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6074 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6075 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6076 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6077 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6078 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6079 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6080 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6081 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6082 | // CONNECT to mail.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6083 | spdy::SpdyHeaderBlock connect2_block; |
| 6084 | connect2_block[spdy::kHttp2MethodHeader] = "CONNECT"; |
| 6085 | connect2_block[spdy::kHttp2AuthorityHeader] = "mail.example.org:443"; |
| 6086 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6087 | 3, std::move(connect2_block), HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6088 | false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 6089 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6090 | spdy::SpdySerializedFrame conn_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6091 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6092 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6093 | // Fetch https://mail.example.org/ via HTTP. |
| 6094 | const char get2[] = |
| 6095 | "GET / HTTP/1.1\r\n" |
| 6096 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6097 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6098 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6099 | spdy_util_.ConstructSpdyDataFrame(3, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6100 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6101 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6102 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6103 | spdy_util_.ConstructSpdyDataFrame(3, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6104 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6105 | spdy_util_.ConstructSpdyDataFrame(3, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6106 | |
| 6107 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6108 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6109 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6110 | }; |
| 6111 | |
| 6112 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6113 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6114 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 6115 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 6116 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 6117 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 6118 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 6119 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6120 | }; |
| 6121 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6122 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6123 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6124 | |
| 6125 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6126 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6127 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6128 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6129 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6130 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6131 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6132 | |
| 6133 | TestCompletionCallback callback; |
| 6134 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6135 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6136 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6137 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6138 | |
| 6139 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6140 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6141 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6142 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6143 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6144 | ASSERT_TRUE(response); |
| 6145 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6146 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6147 | |
| 6148 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6149 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6150 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6151 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6152 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6153 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6154 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6155 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6156 | |
| 6157 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6158 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6159 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 6160 | // to be created, so the socket's load timing looks like a fresh connection. |
| 6161 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6162 | |
| 6163 | // The requests should have different IDs, since they each are using their own |
| 6164 | // separate stream. |
| 6165 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6166 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6167 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6168 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6169 | } |
| 6170 | |
| 6171 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6172 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6173 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6174 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 6175 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6176 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6177 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6178 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6179 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6180 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6181 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6182 | |
| 6183 | HttpRequestInfo request1; |
| 6184 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6185 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6186 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6187 | request1.traffic_annotation = |
| 6188 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6189 | |
| 6190 | HttpRequestInfo request2; |
| 6191 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6192 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6193 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6194 | request2.traffic_annotation = |
| 6195 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6196 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6197 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6198 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6199 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6200 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6201 | spdy::SpdySerializedFrame conn_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6202 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6203 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6204 | // Fetch https://www.example.org/ via HTTP. |
| 6205 | const char get1[] = |
| 6206 | "GET / HTTP/1.1\r\n" |
| 6207 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6208 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6209 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6210 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6211 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6212 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6213 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6214 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6215 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6216 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6217 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6218 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6219 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6220 | // Fetch https://www.example.org/2 via HTTP. |
| 6221 | const char get2[] = |
| 6222 | "GET /2 HTTP/1.1\r\n" |
| 6223 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6224 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6225 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6226 | spdy_util_.ConstructSpdyDataFrame(1, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6227 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6228 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6229 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6230 | spdy_util_.ConstructSpdyDataFrame(1, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6231 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6232 | spdy_util_.ConstructSpdyDataFrame(1, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6233 | |
| 6234 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6235 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6236 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6237 | }; |
| 6238 | |
| 6239 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6240 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6241 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6242 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6243 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6244 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6245 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6246 | }; |
| 6247 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6248 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6249 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6250 | |
| 6251 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6252 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6253 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6254 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6255 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6256 | |
| 6257 | TestCompletionCallback callback; |
| 6258 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6259 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6260 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6261 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6262 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6263 | |
| 6264 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6265 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6266 | |
| 6267 | LoadTimingInfo load_timing_info; |
| 6268 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6269 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6270 | |
| 6271 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6272 | ASSERT_TRUE(response); |
| 6273 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6274 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6275 | |
| 6276 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6277 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6278 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6279 | trans.reset(); |
| 6280 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6281 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6282 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6283 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6284 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6285 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6286 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6287 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6288 | |
| 6289 | LoadTimingInfo load_timing_info2; |
| 6290 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 6291 | TestLoadTimingReused(load_timing_info2); |
| 6292 | |
| 6293 | // The requests should have the same ID. |
| 6294 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6295 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6296 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6297 | } |
| 6298 | |
| 6299 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 6300 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6301 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6302 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6303 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6304 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6305 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6306 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6307 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6308 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6309 | |
| 6310 | HttpRequestInfo request1; |
| 6311 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6312 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6313 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6314 | request1.traffic_annotation = |
| 6315 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6316 | |
| 6317 | HttpRequestInfo request2; |
| 6318 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6319 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6320 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6321 | request2.traffic_annotation = |
| 6322 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6323 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6324 | // http://www.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6325 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6326 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6327 | spdy::SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6328 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6329 | spdy::SpdySerializedFrame get_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6330 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6331 | spdy::SpdySerializedFrame body1( |
| 6332 | spdy_util_.ConstructSpdyDataFrame(1, "1", true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 6333 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6334 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6335 | // http://mail.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6336 | spdy::SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6337 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6338 | spdy::SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6339 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6340 | spdy::SpdySerializedFrame get_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6341 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6342 | spdy::SpdySerializedFrame body2( |
| 6343 | spdy_util_.ConstructSpdyDataFrame(3, "22", true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6344 | |
| 6345 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6346 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6347 | }; |
| 6348 | |
| 6349 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6350 | CreateMockRead(get_resp1, 1, ASYNC), |
| 6351 | CreateMockRead(body1, 2, ASYNC), |
| 6352 | CreateMockRead(get_resp2, 4, ASYNC), |
| 6353 | CreateMockRead(body2, 5, ASYNC), |
| 6354 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6355 | }; |
| 6356 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6357 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6358 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6359 | |
| 6360 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6361 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6362 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6363 | |
| 6364 | TestCompletionCallback callback; |
| 6365 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6366 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6367 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6368 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6369 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6370 | |
| 6371 | LoadTimingInfo load_timing_info; |
| 6372 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6373 | TestLoadTimingNotReused(load_timing_info, |
| 6374 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6375 | |
| 6376 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6377 | ASSERT_TRUE(response); |
| 6378 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6379 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6380 | |
| 6381 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6382 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6383 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 6384 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6385 | // Delete the first request, so the second one can reuse the socket. |
| 6386 | trans.reset(); |
| 6387 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6388 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6389 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6390 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6391 | |
| 6392 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6393 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6394 | TestLoadTimingReused(load_timing_info2); |
| 6395 | |
| 6396 | // The requests should have the same ID. |
| 6397 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6398 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6399 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6400 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6401 | } |
| 6402 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6403 | // Test that an HTTP/2 CONNECT through an HTTPS Proxy to a HTTP/2 server and a |
| 6404 | // direct (non-proxied) request to the proxy server are not pooled, as that |
| 6405 | // would break socket pool isolation. |
| 6406 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation1) { |
| 6407 | ProxyConfig proxy_config; |
| 6408 | proxy_config.set_auto_detect(true); |
| 6409 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6410 | |
| 6411 | CapturingProxyResolver capturing_proxy_resolver; |
| 6412 | session_deps_.proxy_resolution_service = |
| 6413 | std::make_unique<ProxyResolutionService>( |
| 6414 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6415 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6416 | std::make_unique<CapturingProxyResolverFactory>( |
| 6417 | &capturing_proxy_resolver), |
| 6418 | nullptr); |
| 6419 | |
| 6420 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6421 | |
| 6422 | SpdyTestUtil spdy_util1; |
| 6423 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6424 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6425 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6426 | HostPortPair("www.example.org", 443))); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6427 | // fetch https://www.example.org/ via HTTP/2. |
| 6428 | const char kMyUrl[] = "https://www.example.org/"; |
| 6429 | spdy::SpdySerializedFrame get(spdy_util1.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6430 | spdy::SpdySerializedFrame wrapped_get( |
| 6431 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6432 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6433 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6434 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6435 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6436 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6437 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6438 | spdy::SpdySerializedFrame body(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6439 | spdy::SpdySerializedFrame wrapped_body( |
| 6440 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6441 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6442 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6443 | spdy::SpdySerializedFrame window_update_body( |
| 6444 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6445 | |
| 6446 | MockWrite spdy_writes1[] = { |
| 6447 | CreateMockWrite(connect, 0), |
| 6448 | CreateMockWrite(wrapped_get, 2), |
| 6449 | CreateMockWrite(window_update_get_resp, 6), |
| 6450 | CreateMockWrite(window_update_body, 7), |
| 6451 | }; |
| 6452 | |
| 6453 | MockRead spdy_reads1[] = { |
| 6454 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6455 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6456 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6457 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6458 | MockRead(ASYNC, 0, 8), |
| 6459 | }; |
| 6460 | |
| 6461 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6462 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6463 | |
| 6464 | // Fetch https://proxy:70/ via HTTP/2. Needs a new SpdyTestUtil, since it uses |
| 6465 | // a new pipe. |
| 6466 | SpdyTestUtil spdy_util2; |
| 6467 | spdy::SpdySerializedFrame req( |
| 6468 | spdy_util2.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6469 | MockWrite spdy_writes2[] = {CreateMockWrite(req, 0)}; |
| 6470 | |
| 6471 | spdy::SpdySerializedFrame resp( |
| 6472 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6473 | spdy::SpdySerializedFrame data(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6474 | MockRead spdy_reads2[] = { |
| 6475 | CreateMockRead(resp, 1), |
| 6476 | CreateMockRead(data, 2), |
| 6477 | MockRead(ASYNC, 0, 3), |
| 6478 | }; |
| 6479 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6480 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6481 | |
| 6482 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6483 | ssl.next_proto = kProtoHTTP2; |
| 6484 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6485 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6486 | ssl2.next_proto = kProtoHTTP2; |
| 6487 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6488 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6489 | ssl3.next_proto = kProtoHTTP2; |
| 6490 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6491 | |
| 6492 | TestCompletionCallback callback; |
| 6493 | std::string response_data; |
| 6494 | |
| 6495 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6496 | capturing_proxy_resolver.set_proxy_server( |
| 6497 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6498 | HttpRequestInfo request1; |
| 6499 | request1.method = "GET"; |
| 6500 | request1.url = GURL("https://www.example.org/"); |
| 6501 | request1.traffic_annotation = |
| 6502 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6503 | |
| 6504 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6505 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 6506 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6507 | |
| 6508 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6509 | base::RunLoop().RunUntilIdle(); |
| 6510 | // Now allow the read of the response to complete. |
| 6511 | spdy_data1.Resume(); |
| 6512 | rv = callback.WaitForResult(); |
| 6513 | EXPECT_THAT(rv, IsOk()); |
| 6514 | |
| 6515 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 6516 | ASSERT_TRUE(response); |
| 6517 | ASSERT_TRUE(response->headers); |
| 6518 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6519 | |
| 6520 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6521 | EXPECT_EQ(kUploadData, response_data); |
| 6522 | RunUntilIdle(); |
| 6523 | |
| 6524 | // Make a direct HTTP/2 request to proxy:70. |
| 6525 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6526 | HttpRequestInfo request2; |
| 6527 | request2.method = "GET"; |
| 6528 | request2.url = GURL("https://proxy:70/"); |
| 6529 | request2.traffic_annotation = |
| 6530 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6531 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6532 | EXPECT_THAT(callback.GetResult(trans2.Start(&request2, callback.callback(), |
| 6533 | NetLogWithSource())), |
| 6534 | IsOk()); |
| 6535 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6536 | } |
| 6537 | |
| 6538 | // Same as above, but reverse request order, since the code to check for an |
| 6539 | // existing session is different for tunnels and direct connections. |
| 6540 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation2) { |
| 6541 | // Configure against https proxy server "myproxy:80". |
| 6542 | ProxyConfig proxy_config; |
| 6543 | proxy_config.set_auto_detect(true); |
| 6544 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6545 | |
| 6546 | CapturingProxyResolver capturing_proxy_resolver; |
| 6547 | session_deps_.proxy_resolution_service = |
| 6548 | std::make_unique<ProxyResolutionService>( |
| 6549 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6550 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6551 | std::make_unique<CapturingProxyResolverFactory>( |
| 6552 | &capturing_proxy_resolver), |
| 6553 | nullptr); |
| 6554 | |
| 6555 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6556 | // Fetch https://proxy:70/ via HTTP/2. |
| 6557 | SpdyTestUtil spdy_util1; |
| 6558 | spdy::SpdySerializedFrame req( |
| 6559 | spdy_util1.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6560 | MockWrite spdy_writes1[] = {CreateMockWrite(req, 0)}; |
| 6561 | |
| 6562 | spdy::SpdySerializedFrame resp( |
| 6563 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6564 | spdy::SpdySerializedFrame data(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6565 | MockRead spdy_reads1[] = { |
| 6566 | CreateMockRead(resp, 1), |
| 6567 | CreateMockRead(data, 2), |
| 6568 | MockRead(ASYNC, 0, 3), |
| 6569 | }; |
| 6570 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6571 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6572 | |
| 6573 | SpdyTestUtil spdy_util2; |
| 6574 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6575 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6576 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6577 | HostPortPair("www.example.org", 443))); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6578 | // fetch https://www.example.org/ via HTTP/2. |
| 6579 | const char kMyUrl[] = "https://www.example.org/"; |
| 6580 | spdy::SpdySerializedFrame get(spdy_util2.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6581 | spdy::SpdySerializedFrame wrapped_get( |
| 6582 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6583 | spdy::SpdySerializedFrame conn_resp( |
| 6584 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6585 | spdy::SpdySerializedFrame get_resp( |
| 6586 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6587 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6588 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6589 | spdy::SpdySerializedFrame body(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6590 | spdy::SpdySerializedFrame wrapped_body( |
| 6591 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6592 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6593 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6594 | spdy::SpdySerializedFrame window_update_body( |
| 6595 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6596 | |
| 6597 | MockWrite spdy_writes2[] = { |
| 6598 | CreateMockWrite(connect, 0), |
| 6599 | CreateMockWrite(wrapped_get, 2), |
| 6600 | CreateMockWrite(window_update_get_resp, 6), |
| 6601 | CreateMockWrite(window_update_body, 7), |
| 6602 | }; |
| 6603 | |
| 6604 | MockRead spdy_reads2[] = { |
| 6605 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6606 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6607 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6608 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6609 | MockRead(ASYNC, 0, 8), |
| 6610 | }; |
| 6611 | |
| 6612 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6613 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6614 | |
| 6615 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6616 | ssl.next_proto = kProtoHTTP2; |
| 6617 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6618 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6619 | ssl2.next_proto = kProtoHTTP2; |
| 6620 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6621 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6622 | ssl3.next_proto = kProtoHTTP2; |
| 6623 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6624 | |
| 6625 | TestCompletionCallback callback; |
| 6626 | std::string response_data; |
| 6627 | |
| 6628 | // Make a direct HTTP/2 request to proxy:70. |
| 6629 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6630 | HttpRequestInfo request1; |
| 6631 | request1.method = "GET"; |
| 6632 | request1.url = GURL("https://proxy:70/"); |
| 6633 | request1.traffic_annotation = |
| 6634 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6635 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6636 | EXPECT_THAT(callback.GetResult(trans1.Start(&request1, callback.callback(), |
| 6637 | NetLogWithSource())), |
| 6638 | IsOk()); |
| 6639 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6640 | RunUntilIdle(); |
| 6641 | |
| 6642 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6643 | capturing_proxy_resolver.set_proxy_server( |
| 6644 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6645 | HttpRequestInfo request2; |
| 6646 | request2.method = "GET"; |
| 6647 | request2.url = GURL("https://www.example.org/"); |
| 6648 | request2.traffic_annotation = |
| 6649 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6650 | |
| 6651 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6652 | int rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 6653 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6654 | |
| 6655 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6656 | base::RunLoop().RunUntilIdle(); |
| 6657 | // Now allow the read of the response to complete. |
| 6658 | spdy_data2.Resume(); |
| 6659 | rv = callback.WaitForResult(); |
| 6660 | EXPECT_THAT(rv, IsOk()); |
| 6661 | |
| 6662 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 6663 | ASSERT_TRUE(response2); |
| 6664 | ASSERT_TRUE(response2->headers); |
| 6665 | EXPECT_EQ("HTTP/1.1 200", response2->headers->GetStatusLine()); |
| 6666 | |
| 6667 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6668 | EXPECT_EQ(kUploadData, response_data); |
| 6669 | } |
| 6670 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6671 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6672 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6673 | HttpRequestInfo request; |
| 6674 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6675 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6676 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 6677 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6678 | request.traffic_annotation = |
| 6679 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6680 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6681 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6682 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6683 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6684 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6685 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6686 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6687 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6688 | // Since we have proxy, should use full url |
| 6689 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6690 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6691 | "Host: www.example.org\r\n" |
| 6692 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6693 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6694 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6695 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6696 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6697 | "Host: www.example.org\r\n" |
| 6698 | "Proxy-Connection: keep-alive\r\n" |
| 6699 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6700 | }; |
| 6701 | |
| 6702 | // The proxy responds to the GET with a 407, using a persistent |
| 6703 | // connection. |
| 6704 | MockRead data_reads1[] = { |
| 6705 | // No credentials. |
| 6706 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 6707 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6708 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 6709 | MockRead("Content-Length: 0\r\n\r\n"), |
| 6710 | |
| 6711 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6712 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6713 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6714 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6715 | }; |
| 6716 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6717 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6718 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6719 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6720 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6721 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6722 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6723 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6724 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6725 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6726 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6727 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6728 | |
| 6729 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6730 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6731 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6732 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6733 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6734 | TestLoadTimingNotReused(load_timing_info, |
| 6735 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6736 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6737 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6738 | ASSERT_TRUE(response); |
| 6739 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6740 | EXPECT_EQ(407, response->headers->response_code()); |
| 6741 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 6742 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6743 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6744 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6745 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6746 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6747 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6748 | |
| 6749 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6750 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6751 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6752 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6753 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6754 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 6755 | TestLoadTimingReused(load_timing_info); |
| 6756 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6757 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6758 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6759 | |
| 6760 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6761 | EXPECT_EQ(200, response->headers->response_code()); |
| 6762 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6763 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6764 | |
| 6765 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6766 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6767 | } |
| 6768 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6769 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6770 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6771 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6772 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6773 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6774 | request.traffic_annotation = |
| 6775 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6776 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6777 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6778 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6779 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6780 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6781 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6782 | // Since we have proxy, should try to establish tunnel. |
| 6783 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6784 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6785 | "Host: www.example.org:443\r\n" |
| 6786 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6787 | }; |
| 6788 | |
| 6789 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6790 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 6791 | // No response body because the test stops reading here. |
| 6792 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6793 | }; |
| 6794 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6795 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6796 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6797 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6798 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6799 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6800 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6801 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6802 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6803 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6804 | |
| 6805 | rv = callback.WaitForResult(); |
| 6806 | EXPECT_EQ(expected_status, rv); |
| 6807 | } |
| 6808 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6809 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 6810 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6811 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6812 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6813 | } |
| 6814 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6815 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6816 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 6817 | } |
| 6818 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6819 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6820 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 6821 | } |
| 6822 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6823 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6824 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 6825 | } |
| 6826 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6827 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6828 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 6829 | } |
| 6830 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6831 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6832 | ConnectStatusHelper( |
| 6833 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 6834 | } |
| 6835 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6836 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6837 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 6838 | } |
| 6839 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6840 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6841 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 6842 | } |
| 6843 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6844 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6845 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 6846 | } |
| 6847 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6848 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6849 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 6850 | } |
| 6851 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6852 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6853 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 6854 | } |
| 6855 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6856 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6857 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 6858 | } |
| 6859 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6860 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6861 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 6862 | } |
| 6863 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6864 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6865 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 6866 | } |
| 6867 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6868 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6869 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 6870 | } |
| 6871 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6872 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6873 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 6874 | } |
| 6875 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6876 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6877 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 6878 | } |
| 6879 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6880 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 6881 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 6882 | } |
| 6883 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6884 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6885 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 6886 | } |
| 6887 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6888 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6889 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 6890 | } |
| 6891 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6892 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6893 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 6894 | } |
| 6895 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6896 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6897 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 6898 | } |
| 6899 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6900 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6901 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 6902 | } |
| 6903 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6904 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6905 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 6906 | } |
| 6907 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6908 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6909 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 6910 | } |
| 6911 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6912 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6913 | ConnectStatusHelperWithExpectedStatus( |
| 6914 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 6915 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6916 | } |
| 6917 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6918 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6919 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 6920 | } |
| 6921 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6922 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6923 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 6924 | } |
| 6925 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6926 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6927 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 6928 | } |
| 6929 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6930 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6931 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 6932 | } |
| 6933 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6934 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6935 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 6936 | } |
| 6937 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6938 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6939 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 6940 | } |
| 6941 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6942 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6943 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 6944 | } |
| 6945 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6946 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6947 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 6948 | } |
| 6949 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6950 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6951 | ConnectStatusHelper( |
| 6952 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 6953 | } |
| 6954 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6955 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6956 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 6957 | } |
| 6958 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6959 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6960 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 6961 | } |
| 6962 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6963 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6964 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 6965 | } |
| 6966 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6967 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6968 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 6969 | } |
| 6970 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6971 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6972 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 6973 | } |
| 6974 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6975 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6976 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 6977 | } |
| 6978 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6979 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6980 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 6981 | } |
| 6982 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6983 | // Test the flow when both the proxy server AND origin server require |
| 6984 | // authentication. Again, this uses basic auth for both since that is |
| 6985 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6986 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6987 | HttpRequestInfo request; |
| 6988 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6989 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6990 | request.traffic_annotation = |
| 6991 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6992 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6993 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6994 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6995 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6996 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6997 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6998 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6999 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7000 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7001 | MockWrite( |
| 7002 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7003 | "Host: www.example.org\r\n" |
| 7004 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7005 | }; |
| 7006 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7007 | MockRead data_reads1[] = { |
| 7008 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 7009 | // Give a couple authenticate options (only the middle one is actually |
| 7010 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 7011 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7012 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7013 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 7014 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7015 | // Large content-length -- won't matter, as connection will be reset. |
| 7016 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7017 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7018 | }; |
| 7019 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7020 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7021 | // request we should be issuing -- the final header line contains the |
| 7022 | // proxy's credentials. |
| 7023 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7024 | MockWrite( |
| 7025 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7026 | "Host: www.example.org\r\n" |
| 7027 | "Proxy-Connection: keep-alive\r\n" |
| 7028 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7029 | }; |
| 7030 | |
| 7031 | // Now the proxy server lets the request pass through to origin server. |
| 7032 | // The origin server responds with a 401. |
| 7033 | MockRead data_reads2[] = { |
| 7034 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7035 | // Note: We are using the same realm-name as the proxy server. This is |
| 7036 | // completely valid, as realms are unique across hosts. |
| 7037 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7038 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7039 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7040 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7041 | }; |
| 7042 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7043 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7044 | // the credentials for both the proxy and origin server. |
| 7045 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7046 | MockWrite( |
| 7047 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7048 | "Host: www.example.org\r\n" |
| 7049 | "Proxy-Connection: keep-alive\r\n" |
| 7050 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 7051 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7052 | }; |
| 7053 | |
| 7054 | // Lastly we get the desired content. |
| 7055 | MockRead data_reads3[] = { |
| 7056 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7057 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7058 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7059 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7060 | }; |
| 7061 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7062 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7063 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7064 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7065 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7066 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7067 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7068 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7069 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7070 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7071 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7072 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7073 | |
| 7074 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7075 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7076 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7077 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7078 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7079 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7080 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7081 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7082 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7083 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7084 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7085 | |
| 7086 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7087 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7088 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7089 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7090 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7091 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7092 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7093 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7094 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7095 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7096 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7097 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7098 | |
| 7099 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7100 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7101 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7102 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7103 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7104 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7105 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7106 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7107 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 7108 | // can't hook into its internals to cause it to generate predictable NTLM |
| 7109 | // authorization headers. |
| 7110 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7111 | // The NTLM authentication unit tests are based on known test data from the |
| 7112 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 7113 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 7114 | // for the implementation and testing of the protocol. |
| 7115 | // |
| 7116 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7117 | |
| 7118 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7119 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7120 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7121 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7122 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7123 | request.traffic_annotation = |
| 7124 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7125 | |
| 7126 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7127 | // to other auth schemes. |
| 7128 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7129 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7130 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7131 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7132 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7133 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7134 | // Generate the NTLM messages based on known test data. |
| 7135 | std::string negotiate_msg; |
| 7136 | std::string challenge_msg; |
| 7137 | std::string authenticate_msg; |
| 7138 | base::Base64Encode( |
| 7139 | base::StringPiece( |
| 7140 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7141 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7142 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7143 | base::Base64Encode( |
| 7144 | base::StringPiece( |
| 7145 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7146 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7147 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7148 | base::Base64Encode( |
| 7149 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7150 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7151 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7152 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7153 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7154 | &authenticate_msg); |
| 7155 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7156 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7157 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7158 | "Host: server\r\n" |
| 7159 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7160 | }; |
| 7161 | |
| 7162 | MockRead data_reads1[] = { |
| 7163 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7164 | // Negotiate and NTLM are often requested together. However, we only want |
| 7165 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7166 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7167 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7168 | MockRead("Connection: close\r\n"), |
| 7169 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7170 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7171 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7172 | }; |
| 7173 | |
| 7174 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7175 | // After restarting with a null identity, this is the |
| 7176 | // request we should be issuing -- the final header line contains a Type |
| 7177 | // 1 message. |
| 7178 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7179 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7180 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7181 | "Authorization: NTLM "), |
| 7182 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7183 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7184 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7185 | // (using correct credentials). The second request continues on the |
| 7186 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7187 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7188 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7189 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7190 | "Authorization: NTLM "), |
| 7191 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7192 | }; |
| 7193 | |
| 7194 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7195 | // The origin server responds with a Type 2 message. |
| 7196 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7197 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7198 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7199 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7200 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7201 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7202 | // Lastly we get the desired content. |
| 7203 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7204 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7205 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7206 | }; |
| 7207 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7208 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7209 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7210 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7211 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7212 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7213 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7214 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7215 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7216 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7217 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7218 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7219 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7220 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7221 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7222 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7223 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7224 | |
| 7225 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7226 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7227 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7228 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7229 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7230 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7231 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7232 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7233 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7234 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7235 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7236 | rv = trans.RestartWithAuth( |
| 7237 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7238 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7239 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7240 | |
| 7241 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7242 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7243 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7244 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7245 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7246 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7247 | ASSERT_TRUE(response); |
| 7248 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7249 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7250 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7251 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7252 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7253 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7254 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7255 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7256 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7257 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7258 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7259 | ASSERT_TRUE(response); |
| 7260 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7261 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7262 | |
| 7263 | std::string response_data; |
| 7264 | rv = ReadTransaction(&trans, &response_data); |
| 7265 | EXPECT_THAT(rv, IsOk()); |
| 7266 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7267 | |
| 7268 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7269 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7270 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7271 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7272 | } |
| 7273 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7274 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7275 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7276 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7277 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7278 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7279 | request.traffic_annotation = |
| 7280 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7281 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7282 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7283 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7284 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7285 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7286 | // Generate the NTLM messages based on known test data. |
| 7287 | std::string negotiate_msg; |
| 7288 | std::string challenge_msg; |
| 7289 | std::string authenticate_msg; |
| 7290 | base::Base64Encode( |
| 7291 | base::StringPiece( |
| 7292 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7293 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7294 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7295 | base::Base64Encode( |
| 7296 | base::StringPiece( |
| 7297 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7298 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7299 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7300 | base::Base64Encode( |
| 7301 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7302 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7303 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7304 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7305 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7306 | &authenticate_msg); |
| 7307 | |
| 7308 | // The authenticate message when |kWrongPassword| is sent. |
| 7309 | std::string wrong_password_authenticate_msg( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7310 | "TlRMTVNTUAADAAAAGAAYAFgAAACKAIoAcAAAAAwADAD6AAAACAAIAAYBAAAQABAADgEAAAAA" |
| 7311 | "AABYAAAAA4IIAAAAAAAAAAAAAPknEYqtJQtusopDRSfYzAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 7312 | "AAAAAOtVz38osnFdRRggUQHUJ3EBAQAAAAAAAIALyP0A1NIBqqqqqqqqqqoAAAAAAgAMAEQA" |
| 7313 | "bwBtAGEAaQBuAAEADABTAGUAcgB2AGUAcgAGAAQAAgAAAAoAEAAAAAAAAAAAAAAAAAAAAAAA" |
| 7314 | "CQAWAEgAVABUAFAALwBzAGUAcgB2AGUAcgAAAAAAAAAAAEQAbwBtAGEAaQBuAFUAcwBlAHIA" |
| 7315 | "QwBPAE0AUABVAFQARQBSAA=="); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7316 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7317 | // Sanity check that it's the same length as the correct authenticate message |
| 7318 | // and that it's different. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7319 | ASSERT_EQ(authenticate_msg.length(), |
| 7320 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7321 | ASSERT_NE(authenticate_msg, wrong_password_authenticate_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7322 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7323 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7324 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7325 | "Host: server\r\n" |
| 7326 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7327 | }; |
| 7328 | |
| 7329 | MockRead data_reads1[] = { |
| 7330 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7331 | // Negotiate and NTLM are often requested together. However, we only want |
| 7332 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7333 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7334 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7335 | MockRead("Connection: close\r\n"), |
| 7336 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7337 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7338 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7339 | }; |
| 7340 | |
| 7341 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7342 | // After restarting with a null identity, this is the |
| 7343 | // request we should be issuing -- the final header line contains a Type |
| 7344 | // 1 message. |
| 7345 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7346 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7347 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7348 | "Authorization: NTLM "), |
| 7349 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7350 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7351 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7352 | // (using incorrect credentials). The second request continues on the |
| 7353 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7354 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7355 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7356 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7357 | "Authorization: NTLM "), |
| 7358 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7359 | }; |
| 7360 | |
| 7361 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7362 | // The origin server responds with a Type 2 message. |
| 7363 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7364 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7365 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 7366 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7367 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7368 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7369 | // Wrong password. |
| 7370 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7371 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 7372 | MockRead("Content-Length: 42\r\n"), |
| 7373 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7374 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7375 | }; |
| 7376 | |
| 7377 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7378 | // After restarting with a null identity, this is the |
| 7379 | // request we should be issuing -- the final header line contains a Type |
| 7380 | // 1 message. |
| 7381 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7382 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7383 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7384 | "Authorization: NTLM "), |
| 7385 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7386 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7387 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7388 | // (the credentials for the origin server). The second request continues |
| 7389 | // on the same connection. |
| 7390 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7391 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7392 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7393 | "Authorization: NTLM "), |
| 7394 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7395 | }; |
| 7396 | |
| 7397 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7398 | // The origin server responds with a Type 2 message. |
| 7399 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7400 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7401 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7402 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7403 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7404 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7405 | // Lastly we get the desired content. |
| 7406 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7407 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7408 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7409 | }; |
| 7410 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7411 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7412 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7413 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7414 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7415 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7416 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7417 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7418 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7419 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7420 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7421 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7422 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 7423 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 7424 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7425 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7426 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7427 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7428 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7429 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7430 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7431 | |
| 7432 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7433 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7434 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7435 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7436 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7437 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7438 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7439 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7440 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7441 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7442 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7443 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7444 | rv = trans.RestartWithAuth( |
| 7445 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 7446 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7447 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7448 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7449 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7450 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7451 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7452 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7453 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7454 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7455 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7456 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7457 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7458 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7459 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7460 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7461 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7462 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7463 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7464 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7465 | |
| 7466 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7467 | rv = trans.RestartWithAuth( |
| 7468 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7469 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7470 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7471 | |
| 7472 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7473 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7474 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7475 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7476 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7477 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7478 | |
| 7479 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7480 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7481 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7482 | |
| 7483 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7484 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7485 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7486 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7487 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7488 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7489 | |
| 7490 | std::string response_data; |
| 7491 | rv = ReadTransaction(&trans, &response_data); |
| 7492 | EXPECT_THAT(rv, IsOk()); |
| 7493 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7494 | |
| 7495 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7496 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7497 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7498 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 7499 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 7500 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7501 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7502 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7503 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 7504 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7505 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7506 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7507 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7508 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7509 | const char* kUrl = "https://server/kids/login.aspx"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7510 | |
| 7511 | HttpRequestInfo request; |
| 7512 | request.method = "GET"; |
| 7513 | request.url = GURL(kUrl); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7514 | request.traffic_annotation = |
| 7515 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7516 | |
| 7517 | // First request without credentials. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7518 | spdy::SpdyHeaderBlock request_headers0( |
| 7519 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 7520 | spdy::SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7521 | 1, std::move(request_headers0), LOWEST, true)); |
| 7522 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7523 | spdy::SpdyHeaderBlock response_headers0; |
| 7524 | response_headers0[spdy::kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7525 | response_headers0["www-authenticate"] = "NTLM"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7526 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7527 | 1, std::move(response_headers0), true)); |
| 7528 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7529 | // Stream 1 is closed. |
| 7530 | spdy_util_.UpdateWithStreamDestruction(1); |
| 7531 | |
| 7532 | // Generate the NTLM messages based on known test data. |
| 7533 | std::string negotiate_msg; |
| 7534 | std::string challenge_msg; |
| 7535 | std::string authenticate_msg; |
| 7536 | base::Base64Encode( |
| 7537 | base::StringPiece( |
| 7538 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7539 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7540 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7541 | base::Base64Encode( |
| 7542 | base::StringPiece( |
| 7543 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7544 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7545 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7546 | base::Base64Encode( |
| 7547 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7548 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7549 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7550 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7551 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7552 | &authenticate_msg); |
| 7553 | |
| 7554 | // Retry with authorization header. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7555 | spdy::SpdyHeaderBlock request_headers1( |
| 7556 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7557 | request_headers1["authorization"] = std::string("NTLM ") + negotiate_msg; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7558 | spdy::SpdySerializedFrame request1(spdy_util_.ConstructSpdyHeaders( |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7559 | 3, std::move(request_headers1), LOWEST, true)); |
| 7560 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7561 | spdy::SpdySerializedFrame rst( |
| 7562 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_HTTP_1_1_REQUIRED)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7563 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7564 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
| 7565 | MockRead reads0[] = {CreateMockRead(resp, 1), MockRead(ASYNC, 0, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7566 | |
| 7567 | // Retry yet again using HTTP/1.1. |
| 7568 | MockWrite writes1[] = { |
| 7569 | // After restarting with a null identity, this is the |
| 7570 | // request we should be issuing -- the final header line contains a Type |
| 7571 | // 1 message. |
| 7572 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7573 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7574 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7575 | "Authorization: NTLM "), |
| 7576 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7577 | |
| 7578 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7579 | // (the credentials for the origin server). The second request continues |
| 7580 | // on the same connection. |
| 7581 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7582 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7583 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7584 | "Authorization: NTLM "), |
| 7585 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7586 | }; |
| 7587 | |
| 7588 | MockRead reads1[] = { |
| 7589 | // The origin server responds with a Type 2 message. |
| 7590 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7591 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7592 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7593 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7594 | MockRead("You are not authorized to view this page\r\n"), |
| 7595 | |
| 7596 | // Lastly we get the desired content. |
| 7597 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7598 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7599 | 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] | 7600 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7601 | SequencedSocketData data0(reads0, writes0); |
| 7602 | StaticSocketDataProvider data1(reads1, writes1); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7603 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 7604 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7605 | |
| 7606 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 7607 | ssl0.next_proto = kProtoHTTP2; |
| 7608 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7609 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 7610 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7611 | |
| 7612 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7613 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7614 | |
| 7615 | TestCompletionCallback callback1; |
| 7616 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 7617 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7618 | |
| 7619 | rv = callback1.WaitForResult(); |
| 7620 | EXPECT_THAT(rv, IsOk()); |
| 7621 | |
| 7622 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7623 | |
| 7624 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7625 | ASSERT_TRUE(response); |
| 7626 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
| 7627 | |
| 7628 | TestCompletionCallback callback2; |
| 7629 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7630 | rv = trans.RestartWithAuth( |
| 7631 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7632 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7633 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7634 | |
| 7635 | rv = callback2.WaitForResult(); |
| 7636 | EXPECT_THAT(rv, IsOk()); |
| 7637 | |
| 7638 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7639 | |
| 7640 | response = trans.GetResponseInfo(); |
| 7641 | ASSERT_TRUE(response); |
| 7642 | EXPECT_FALSE(response->auth_challenge); |
| 7643 | |
| 7644 | TestCompletionCallback callback3; |
| 7645 | |
| 7646 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 7647 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7648 | |
| 7649 | rv = callback3.WaitForResult(); |
| 7650 | EXPECT_THAT(rv, IsOk()); |
| 7651 | |
| 7652 | response = trans.GetResponseInfo(); |
| 7653 | ASSERT_TRUE(response); |
| 7654 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7655 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7656 | |
| 7657 | std::string response_data; |
| 7658 | rv = ReadTransaction(&trans, &response_data); |
| 7659 | EXPECT_THAT(rv, IsOk()); |
| 7660 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7661 | |
| 7662 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 7663 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 7664 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7665 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7666 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7667 | |
| 7668 | // Test that, if we have an NTLM proxy and the origin resets the connection, we |
| 7669 | // do no retry forever checking for TLS version interference. This is a |
| 7670 | // regression test for https://crbug.com/823387. |
| 7671 | TEST_F(HttpNetworkTransactionTest, NTLMProxyTLSHandshakeReset) { |
| 7672 | // The NTLM test data expects the proxy to be named 'server'. The origin is |
| 7673 | // https://origin/. |
| 7674 | session_deps_.proxy_resolution_service = |
| 7675 | ProxyResolutionService::CreateFixedFromPacResult( |
| 7676 | "PROXY server", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7677 | |
| 7678 | SSLConfig config; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7679 | session_deps_.ssl_config_service = |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 7680 | std::make_unique<TestSSLConfigService>(config); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7681 | |
| 7682 | HttpRequestInfo request; |
| 7683 | request.method = "GET"; |
| 7684 | request.url = GURL("https://origin/"); |
| 7685 | request.traffic_annotation = |
| 7686 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7687 | |
| 7688 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7689 | // to other auth schemes. |
| 7690 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 7691 | |
| 7692 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7693 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
| 7694 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7695 | |
| 7696 | // Generate the NTLM messages based on known test data. |
| 7697 | std::string negotiate_msg; |
| 7698 | std::string challenge_msg; |
| 7699 | std::string authenticate_msg; |
| 7700 | base::Base64Encode( |
| 7701 | base::StringPiece( |
| 7702 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7703 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7704 | &negotiate_msg); |
| 7705 | base::Base64Encode( |
| 7706 | base::StringPiece( |
| 7707 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7708 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7709 | &challenge_msg); |
| 7710 | base::Base64Encode( |
| 7711 | base::StringPiece( |
| 7712 | reinterpret_cast<const char*>( |
| 7713 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7714 | base::size( |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7715 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
| 7716 | &authenticate_msg); |
| 7717 | |
| 7718 | MockWrite data_writes[] = { |
| 7719 | // The initial CONNECT request. |
| 7720 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7721 | "Host: origin:443\r\n" |
| 7722 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7723 | |
| 7724 | // After restarting with an identity. |
| 7725 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7726 | "Host: origin:443\r\n" |
| 7727 | "Proxy-Connection: keep-alive\r\n" |
| 7728 | "Proxy-Authorization: NTLM "), |
| 7729 | MockWrite(negotiate_msg.c_str()), |
| 7730 | // End headers. |
| 7731 | MockWrite("\r\n\r\n"), |
| 7732 | |
| 7733 | // The second restart. |
| 7734 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7735 | "Host: origin:443\r\n" |
| 7736 | "Proxy-Connection: keep-alive\r\n" |
| 7737 | "Proxy-Authorization: NTLM "), |
| 7738 | MockWrite(authenticate_msg.c_str()), |
| 7739 | // End headers. |
| 7740 | MockWrite("\r\n\r\n"), |
| 7741 | }; |
| 7742 | |
| 7743 | MockRead data_reads[] = { |
| 7744 | // The initial NTLM response. |
| 7745 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 7746 | "Content-Length: 0\r\n" |
| 7747 | "Proxy-Authenticate: NTLM\r\n\r\n"), |
| 7748 | |
| 7749 | // The NTLM challenge message. |
| 7750 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 7751 | "Content-Length: 0\r\n" |
| 7752 | "Proxy-Authenticate: NTLM "), |
| 7753 | MockRead(challenge_msg.c_str()), |
| 7754 | // End headers. |
| 7755 | MockRead("\r\n\r\n"), |
| 7756 | |
| 7757 | // Finally the tunnel is established. |
| 7758 | MockRead("HTTP/1.1 200 Connected\r\n\r\n"), |
| 7759 | }; |
| 7760 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7761 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7762 | SSLSocketDataProvider data_ssl(ASYNC, ERR_CONNECTION_RESET); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7763 | StaticSocketDataProvider data2(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7764 | SSLSocketDataProvider data_ssl2(ASYNC, ERR_CONNECTION_RESET); |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 7765 | data_ssl2.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7766 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7767 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl); |
| 7768 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7769 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl2); |
| 7770 | |
| 7771 | // Start the transaction. The proxy responds with an NTLM authentication |
| 7772 | // request. |
| 7773 | TestCompletionCallback callback; |
| 7774 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7775 | int rv = callback.GetResult( |
| 7776 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 7777 | |
| 7778 | EXPECT_THAT(rv, IsOk()); |
| 7779 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7780 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7781 | ASSERT_TRUE(response); |
| 7782 | EXPECT_TRUE(CheckNTLMProxyAuth(response->auth_challenge.get())); |
| 7783 | |
| 7784 | // Configure credentials. The proxy responds with the challenge message. |
| 7785 | rv = callback.GetResult(trans.RestartWithAuth( |
| 7786 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7787 | callback.callback())); |
| 7788 | EXPECT_THAT(rv, IsOk()); |
| 7789 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7790 | response = trans.GetResponseInfo(); |
| 7791 | ASSERT_TRUE(response); |
| 7792 | EXPECT_FALSE(response->auth_challenge); |
| 7793 | |
| 7794 | // Restart once more. The tunnel will be established and the the SSL handshake |
| 7795 | // will reset. The TLS 1.3 version interference probe will then kick in and |
| 7796 | // restart the process. The proxy responds with another NTLM authentiation |
| 7797 | // request, but we don't need to provide credentials as the cached ones work/ |
| 7798 | rv = callback.GetResult( |
| 7799 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7800 | EXPECT_THAT(rv, IsOk()); |
| 7801 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7802 | response = trans.GetResponseInfo(); |
| 7803 | ASSERT_TRUE(response); |
| 7804 | EXPECT_FALSE(response->auth_challenge); |
| 7805 | |
| 7806 | // The proxy responds with the NTLM challenge message. |
| 7807 | rv = callback.GetResult( |
| 7808 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7809 | EXPECT_THAT(rv, IsOk()); |
| 7810 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7811 | response = trans.GetResponseInfo(); |
| 7812 | ASSERT_TRUE(response); |
| 7813 | EXPECT_FALSE(response->auth_challenge); |
| 7814 | |
| 7815 | // Send the NTLM authenticate message. The tunnel is established and the |
| 7816 | // handshake resets again. We should not retry again. |
| 7817 | rv = callback.GetResult( |
| 7818 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7819 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
| 7820 | } |
| 7821 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7822 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7823 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7824 | // Test reading a server response which has only headers, and no body. |
| 7825 | // After some maximum number of bytes is consumed, the transaction should |
| 7826 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7827 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7828 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7829 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7830 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7831 | request.traffic_annotation = |
| 7832 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7833 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7834 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7835 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7836 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7837 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 7838 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7839 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7840 | |
| 7841 | MockRead data_reads[] = { |
| 7842 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7843 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7844 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7845 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7846 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7847 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7848 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7849 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7850 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7851 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7852 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7853 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7854 | |
| 7855 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7856 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7857 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7858 | |
| 7859 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 7860 | // establish tunnel. |
| 7861 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7862 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7863 | HttpRequestInfo request; |
| 7864 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7865 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7866 | request.traffic_annotation = |
| 7867 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7868 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7869 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 7870 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 7871 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 7872 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7873 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7874 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7875 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7876 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7877 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7878 | // Since we have proxy, should try to establish tunnel. |
| 7879 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7880 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7881 | "Host: www.example.org:443\r\n" |
| 7882 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7883 | }; |
| 7884 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7885 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7886 | // connection. Usually a proxy would return 501 (not implemented), |
| 7887 | // or 200 (tunnel established). |
| 7888 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 7889 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7890 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7891 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7892 | }; |
| 7893 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7894 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7895 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7896 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7897 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7898 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7899 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7900 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7901 | |
| 7902 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7903 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7904 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7905 | // Empty the current queue. This is necessary because idle sockets are |
| 7906 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7907 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7908 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7909 | // We now check to make sure the TCPClientSocket was not added back to |
| 7910 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7911 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7912 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7913 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7914 | // Make sure that the socket didn't get recycled after calling the destructor. |
[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 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7917 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7918 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7919 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7920 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7921 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7922 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7923 | request.traffic_annotation = |
| 7924 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7925 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7926 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7927 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7928 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7929 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7930 | MockRead data_reads[] = { |
| 7931 | // A part of the response body is received with the response headers. |
| 7932 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7933 | // The rest of the response body is received in two parts. |
| 7934 | MockRead("lo"), |
| 7935 | MockRead(" world"), |
| 7936 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7937 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7938 | }; |
| 7939 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7940 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7941 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7942 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7943 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7944 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7945 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7946 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7947 | |
| 7948 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7949 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7950 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7951 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7952 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7953 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7954 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7955 | std::string status_line = response->headers->GetStatusLine(); |
| 7956 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7957 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7958 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7959 | |
| 7960 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7961 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7962 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7963 | EXPECT_EQ("hello world", response_data); |
| 7964 | |
| 7965 | // Empty the current queue. This is necessary because idle sockets are |
| 7966 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7967 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7968 | |
| 7969 | // 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] | 7970 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7971 | } |
| 7972 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7973 | // Make sure that we recycle a SSL socket after reading all of the response |
| 7974 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7975 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7976 | HttpRequestInfo request; |
| 7977 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7978 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7979 | request.traffic_annotation = |
| 7980 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7981 | |
| 7982 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7983 | MockWrite( |
| 7984 | "GET / HTTP/1.1\r\n" |
| 7985 | "Host: www.example.org\r\n" |
| 7986 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7987 | }; |
| 7988 | |
| 7989 | MockRead data_reads[] = { |
| 7990 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7991 | MockRead("Content-Length: 11\r\n\r\n"), |
| 7992 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7993 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7994 | }; |
| 7995 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7996 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7997 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7998 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7999 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8000 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8001 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8002 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8003 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8004 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8005 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8006 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8007 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8008 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8009 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8010 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8011 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8012 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8013 | ASSERT_TRUE(response); |
| 8014 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8015 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8016 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8017 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8018 | |
| 8019 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8020 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8021 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8022 | EXPECT_EQ("hello world", response_data); |
| 8023 | |
| 8024 | // Empty the current queue. This is necessary because idle sockets are |
| 8025 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8026 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8027 | |
| 8028 | // 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] | 8029 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8030 | } |
| 8031 | |
| 8032 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 8033 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8034 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8035 | HttpRequestInfo request; |
| 8036 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8037 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8038 | request.traffic_annotation = |
| 8039 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8040 | |
| 8041 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8042 | MockWrite( |
| 8043 | "GET / HTTP/1.1\r\n" |
| 8044 | "Host: www.example.org\r\n" |
| 8045 | "Connection: keep-alive\r\n\r\n"), |
| 8046 | MockWrite( |
| 8047 | "GET / HTTP/1.1\r\n" |
| 8048 | "Host: www.example.org\r\n" |
| 8049 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8050 | }; |
| 8051 | |
| 8052 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 8053 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8054 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8055 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8056 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8057 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8058 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8059 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8060 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8061 | StaticSocketDataProvider data(data_reads, data_writes); |
| 8062 | StaticSocketDataProvider data2(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8063 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8064 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8065 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8066 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8067 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8068 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8069 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8070 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8071 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8072 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8073 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8074 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8075 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8076 | |
| 8077 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8078 | ASSERT_TRUE(response); |
| 8079 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8080 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8081 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8082 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8083 | |
| 8084 | std::string response_data; |
| 8085 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8086 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8087 | EXPECT_EQ("hello world", response_data); |
| 8088 | |
| 8089 | // Empty the current queue. This is necessary because idle sockets are |
| 8090 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8091 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8092 | |
| 8093 | // 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] | 8094 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8095 | |
| 8096 | // Now start the second transaction, which should reuse the previous socket. |
| 8097 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8098 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8099 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8100 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8101 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8102 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8103 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8104 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8105 | |
| 8106 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8107 | ASSERT_TRUE(response); |
| 8108 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8109 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8110 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8111 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8112 | |
| 8113 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8114 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8115 | EXPECT_EQ("hello world", response_data); |
| 8116 | |
| 8117 | // Empty the current queue. This is necessary because idle sockets are |
| 8118 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8119 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8120 | |
| 8121 | // 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] | 8122 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8123 | } |
| 8124 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8125 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8126 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8127 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8128 | HttpRequestInfo request; |
| 8129 | request.method = "GET"; |
| 8130 | request.url = GURL("http://www.example.org/"); |
| 8131 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8132 | request.traffic_annotation = |
| 8133 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8134 | |
| 8135 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8136 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8137 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8138 | |
| 8139 | MockRead data_reads[] = { |
| 8140 | // A part of the response body is received with the response headers. |
| 8141 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8142 | // The rest of the response body is received in two parts. |
| 8143 | MockRead("lo"), MockRead(" world"), |
| 8144 | MockRead("junk"), // Should not be read!! |
| 8145 | MockRead(SYNCHRONOUS, OK), |
| 8146 | }; |
| 8147 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8148 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8149 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8150 | |
| 8151 | TestCompletionCallback callback; |
| 8152 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8153 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8154 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8155 | |
| 8156 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8157 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8158 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8159 | ASSERT_TRUE(response); |
| 8160 | EXPECT_TRUE(response->headers); |
| 8161 | std::string status_line = response->headers->GetStatusLine(); |
| 8162 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8163 | |
| 8164 | // Make memory critical notification and ensure the transaction still has been |
| 8165 | // operating right. |
| 8166 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8167 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8168 | base::RunLoop().RunUntilIdle(); |
| 8169 | |
| 8170 | // Socket should not be flushed as long as it is not idle. |
| 8171 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8172 | |
| 8173 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8174 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8175 | EXPECT_THAT(rv, IsOk()); |
| 8176 | EXPECT_EQ("hello world", response_data); |
| 8177 | |
| 8178 | // Empty the current queue. This is necessary because idle sockets are |
| 8179 | // added to the connection pool asynchronously with a PostTask. |
| 8180 | base::RunLoop().RunUntilIdle(); |
| 8181 | |
| 8182 | // We now check to make sure the socket was added back to the pool. |
| 8183 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8184 | |
| 8185 | // Idle sockets should be flushed now. |
| 8186 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8187 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8188 | base::RunLoop().RunUntilIdle(); |
| 8189 | |
| 8190 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8191 | } |
| 8192 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8193 | // Disable idle socket closing on memory pressure. |
| 8194 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8195 | // low memory notification and ensure the socket pool is NOT flushed. |
| 8196 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 8197 | HttpRequestInfo request; |
| 8198 | request.method = "GET"; |
| 8199 | request.url = GURL("http://www.example.org/"); |
| 8200 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8201 | request.traffic_annotation = |
| 8202 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8203 | |
| 8204 | // Disable idle socket closing on memory pressure. |
| 8205 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 8206 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8207 | |
| 8208 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 8209 | |
| 8210 | MockRead data_reads[] = { |
| 8211 | // A part of the response body is received with the response headers. |
| 8212 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8213 | // The rest of the response body is received in two parts. |
| 8214 | MockRead("lo"), MockRead(" world"), |
| 8215 | MockRead("junk"), // Should not be read!! |
| 8216 | MockRead(SYNCHRONOUS, OK), |
| 8217 | }; |
| 8218 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8219 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8220 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8221 | |
| 8222 | TestCompletionCallback callback; |
| 8223 | |
| 8224 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 8225 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8226 | |
| 8227 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8228 | |
| 8229 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 8230 | ASSERT_TRUE(response); |
| 8231 | EXPECT_TRUE(response->headers); |
| 8232 | std::string status_line = response->headers->GetStatusLine(); |
| 8233 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8234 | |
| 8235 | // Make memory critical notification and ensure the transaction still has been |
| 8236 | // operating right. |
| 8237 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8238 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8239 | base::RunLoop().RunUntilIdle(); |
| 8240 | |
| 8241 | // Socket should not be flushed as long as it is not idle. |
| 8242 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8243 | |
| 8244 | std::string response_data; |
| 8245 | rv = ReadTransaction(&trans, &response_data); |
| 8246 | EXPECT_THAT(rv, IsOk()); |
| 8247 | EXPECT_EQ("hello world", response_data); |
| 8248 | |
| 8249 | // Empty the current queue. This is necessary because idle sockets are |
| 8250 | // added to the connection pool asynchronously with a PostTask. |
| 8251 | base::RunLoop().RunUntilIdle(); |
| 8252 | |
| 8253 | // We now check to make sure the socket was added back to the pool. |
| 8254 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8255 | |
| 8256 | // Idle sockets should NOT be flushed on moderate memory pressure. |
| 8257 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8258 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 8259 | base::RunLoop().RunUntilIdle(); |
| 8260 | |
| 8261 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8262 | |
| 8263 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 8264 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8265 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8266 | base::RunLoop().RunUntilIdle(); |
| 8267 | |
| 8268 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8269 | } |
| 8270 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8271 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 8272 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8273 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8274 | HttpRequestInfo request; |
| 8275 | request.method = "GET"; |
| 8276 | request.url = GURL("https://www.example.org/"); |
| 8277 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8278 | request.traffic_annotation = |
| 8279 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8280 | |
| 8281 | MockWrite data_writes[] = { |
| 8282 | MockWrite("GET / HTTP/1.1\r\n" |
| 8283 | "Host: www.example.org\r\n" |
| 8284 | "Connection: keep-alive\r\n\r\n"), |
| 8285 | }; |
| 8286 | |
| 8287 | MockRead data_reads[] = { |
| 8288 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8289 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 8290 | |
| 8291 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8292 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8293 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8294 | StaticSocketDataProvider data(data_reads, data_writes); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8295 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8296 | |
| 8297 | TestCompletionCallback callback; |
| 8298 | |
| 8299 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8300 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8301 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8302 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8303 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8304 | |
| 8305 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8306 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8307 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8308 | ASSERT_TRUE(response); |
| 8309 | ASSERT_TRUE(response->headers); |
| 8310 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8311 | |
| 8312 | // Make memory critical notification and ensure the transaction still has been |
| 8313 | // operating right. |
| 8314 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8315 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8316 | base::RunLoop().RunUntilIdle(); |
| 8317 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8318 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8319 | |
| 8320 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8321 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8322 | EXPECT_THAT(rv, IsOk()); |
| 8323 | EXPECT_EQ("hello world", response_data); |
| 8324 | |
| 8325 | // Empty the current queue. This is necessary because idle sockets are |
| 8326 | // added to the connection pool asynchronously with a PostTask. |
| 8327 | base::RunLoop().RunUntilIdle(); |
| 8328 | |
| 8329 | // 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] | 8330 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8331 | |
| 8332 | // Make memory notification once again and ensure idle socket is closed. |
| 8333 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8334 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8335 | base::RunLoop().RunUntilIdle(); |
| 8336 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8337 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8338 | } |
| 8339 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8340 | // Make sure that we recycle a socket after a zero-length response. |
| 8341 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8342 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8343 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8344 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8345 | request.url = GURL( |
| 8346 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 8347 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 8348 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 8349 | "rt=prt.2642,ol.2649,xjs.2951"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8350 | request.traffic_annotation = |
| 8351 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8352 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8353 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8354 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8355 | MockRead data_reads[] = { |
| 8356 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 8357 | "Content-Length: 0\r\n" |
| 8358 | "Content-Type: text/html\r\n\r\n"), |
| 8359 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8360 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8361 | }; |
| 8362 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8363 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8364 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8365 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8366 | // Transaction must be created after the MockReads, so it's destroyed before |
| 8367 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8368 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8369 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8370 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8371 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8372 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8373 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8374 | |
| 8375 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8376 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8377 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8378 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8379 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8380 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8381 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8382 | std::string status_line = response->headers->GetStatusLine(); |
| 8383 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 8384 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8385 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8386 | |
| 8387 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8388 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8389 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8390 | EXPECT_EQ("", response_data); |
| 8391 | |
| 8392 | // Empty the current queue. This is necessary because idle sockets are |
| 8393 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8394 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8395 | |
| 8396 | // 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] | 8397 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8398 | } |
| 8399 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8400 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8401 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8402 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8403 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8404 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8405 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8406 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8407 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 8408 | // after use. |
| 8409 | request[0].method = "GET"; |
| 8410 | request[0].url = GURL("http://www.google.com/"); |
| 8411 | request[0].load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8412 | request[0].traffic_annotation = |
| 8413 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8414 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 8415 | // transaction 1. The first attempts fails when writing the POST data. |
| 8416 | // This causes the transaction to retry with a new socket. The second |
| 8417 | // attempt succeeds. |
| 8418 | request[1].method = "POST"; |
| 8419 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8420 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8421 | request[1].load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8422 | request[1].traffic_annotation = |
| 8423 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8424 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8425 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8426 | |
| 8427 | // The first socket is used for transaction 1 and the first attempt of |
| 8428 | // transaction 2. |
| 8429 | |
| 8430 | // The response of transaction 1. |
| 8431 | MockRead data_reads1[] = { |
| 8432 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 8433 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8434 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8435 | }; |
| 8436 | // The mock write results of transaction 1 and the first attempt of |
| 8437 | // transaction 2. |
| 8438 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8439 | MockWrite(SYNCHRONOUS, 64), // GET |
| 8440 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8441 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8442 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8443 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8444 | |
| 8445 | // The second socket is used for the second attempt of transaction 2. |
| 8446 | |
| 8447 | // The response of transaction 2. |
| 8448 | MockRead data_reads2[] = { |
| 8449 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 8450 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8451 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8452 | }; |
| 8453 | // The mock write results of the second attempt of transaction 2. |
| 8454 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8455 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8456 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8457 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8458 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8459 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8460 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8461 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8462 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8463 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8464 | "hello world", "welcome" |
| 8465 | }; |
| 8466 | |
| 8467 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8468 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8469 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8470 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8471 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8472 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8473 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8474 | |
| 8475 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8476 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8477 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8478 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8479 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8480 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8481 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8482 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8483 | |
| 8484 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8485 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8486 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8487 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 8488 | } |
| 8489 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8490 | |
| 8491 | // Test the request-challenge-retry sequence for basic auth when there is |
| 8492 | // 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] | 8493 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8494 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8495 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8496 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8497 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 8498 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8499 | request.traffic_annotation = |
| 8500 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8501 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8502 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8503 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8504 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8505 | // The password contains an escaped character -- for this test to pass it |
| 8506 | // will need to be unescaped by HttpNetworkTransaction. |
| 8507 | EXPECT_EQ("b%40r", request.url.password()); |
| 8508 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8509 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8510 | MockWrite( |
| 8511 | "GET / HTTP/1.1\r\n" |
| 8512 | "Host: www.example.org\r\n" |
| 8513 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8514 | }; |
| 8515 | |
| 8516 | MockRead data_reads1[] = { |
| 8517 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8518 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8519 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8520 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8521 | }; |
| 8522 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8523 | // After the challenge above, the transaction will be restarted using the |
| 8524 | // identity from the url (foo, b@r) to answer the challenge. |
| 8525 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8526 | MockWrite( |
| 8527 | "GET / HTTP/1.1\r\n" |
| 8528 | "Host: www.example.org\r\n" |
| 8529 | "Connection: keep-alive\r\n" |
| 8530 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8531 | }; |
| 8532 | |
| 8533 | MockRead data_reads2[] = { |
| 8534 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8535 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8536 | MockRead(SYNCHRONOUS, OK), |
| 8537 | }; |
| 8538 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8539 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8540 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8541 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8542 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8543 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8544 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8545 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8546 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8547 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8548 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8549 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8550 | |
| 8551 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8552 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8553 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8554 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8555 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8556 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8557 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8558 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8559 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8560 | |
| 8561 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8562 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8563 | |
| 8564 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8565 | |
| 8566 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8567 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8568 | } |
| 8569 | |
| 8570 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 8571 | // incorrect identity in the URL. The identity from the URL should be used only |
| 8572 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8573 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8574 | HttpRequestInfo request; |
| 8575 | request.method = "GET"; |
| 8576 | // Note: the URL has a username:password in it. The password "baz" is |
| 8577 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8578 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8579 | |
| 8580 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8581 | request.traffic_annotation = |
| 8582 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8583 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8584 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8585 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8586 | |
| 8587 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8588 | MockWrite( |
| 8589 | "GET / HTTP/1.1\r\n" |
| 8590 | "Host: www.example.org\r\n" |
| 8591 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8592 | }; |
| 8593 | |
| 8594 | MockRead data_reads1[] = { |
| 8595 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8596 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8597 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8598 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8599 | }; |
| 8600 | |
| 8601 | // After the challenge above, the transaction will be restarted using the |
| 8602 | // identity from the url (foo, baz) to answer the challenge. |
| 8603 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8604 | MockWrite( |
| 8605 | "GET / HTTP/1.1\r\n" |
| 8606 | "Host: www.example.org\r\n" |
| 8607 | "Connection: keep-alive\r\n" |
| 8608 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8609 | }; |
| 8610 | |
| 8611 | MockRead data_reads2[] = { |
| 8612 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8613 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8614 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8615 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8616 | }; |
| 8617 | |
| 8618 | // After the challenge above, the transaction will be restarted using the |
| 8619 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 8620 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8621 | MockWrite( |
| 8622 | "GET / HTTP/1.1\r\n" |
| 8623 | "Host: www.example.org\r\n" |
| 8624 | "Connection: keep-alive\r\n" |
| 8625 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8626 | }; |
| 8627 | |
| 8628 | MockRead data_reads3[] = { |
| 8629 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8630 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8631 | MockRead(SYNCHRONOUS, OK), |
| 8632 | }; |
| 8633 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8634 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8635 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 8636 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8637 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8638 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8639 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8640 | |
| 8641 | TestCompletionCallback callback1; |
| 8642 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8643 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8644 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8645 | |
| 8646 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8647 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8648 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8649 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8650 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8651 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8652 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8653 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8654 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8655 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8656 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8657 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8658 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8659 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 8660 | |
| 8661 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8662 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8663 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8664 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8665 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8666 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8667 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8668 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8669 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8670 | |
| 8671 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8672 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8673 | |
| 8674 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8675 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8676 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8677 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8678 | } |
| 8679 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8680 | |
| 8681 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 8682 | // correct identity in the URL, but its use is being suppressed. The identity |
| 8683 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8684 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8685 | HttpRequestInfo request; |
| 8686 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8687 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8688 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8689 | request.traffic_annotation = |
| 8690 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8691 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8692 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8693 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8694 | |
| 8695 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8696 | MockWrite( |
| 8697 | "GET / HTTP/1.1\r\n" |
| 8698 | "Host: www.example.org\r\n" |
| 8699 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8700 | }; |
| 8701 | |
| 8702 | MockRead data_reads1[] = { |
| 8703 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8704 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8705 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8706 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8707 | }; |
| 8708 | |
| 8709 | // After the challenge above, the transaction will be restarted using the |
| 8710 | // identity supplied by the user, not the one in the URL, to answer the |
| 8711 | // challenge. |
| 8712 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8713 | MockWrite( |
| 8714 | "GET / HTTP/1.1\r\n" |
| 8715 | "Host: www.example.org\r\n" |
| 8716 | "Connection: keep-alive\r\n" |
| 8717 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8718 | }; |
| 8719 | |
| 8720 | MockRead data_reads3[] = { |
| 8721 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8722 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8723 | MockRead(SYNCHRONOUS, OK), |
| 8724 | }; |
| 8725 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8726 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8727 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8728 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8729 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 8730 | |
| 8731 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8732 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8733 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8734 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8735 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8736 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8737 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8738 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8739 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8740 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 8741 | |
| 8742 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8743 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8744 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8745 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8746 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8747 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8748 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8749 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8750 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8751 | |
| 8752 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8753 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8754 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8755 | |
| 8756 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8757 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8758 | } |
| 8759 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8760 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8761 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8762 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8763 | |
| 8764 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 8765 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8766 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8767 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8768 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8769 | request.traffic_annotation = |
| 8770 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8771 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8772 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8773 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8774 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8775 | MockWrite( |
| 8776 | "GET /x/y/z HTTP/1.1\r\n" |
| 8777 | "Host: www.example.org\r\n" |
| 8778 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8779 | }; |
| 8780 | |
| 8781 | MockRead data_reads1[] = { |
| 8782 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8783 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8784 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8785 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8786 | }; |
| 8787 | |
| 8788 | // Resend with authorization (username=foo, password=bar) |
| 8789 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8790 | MockWrite( |
| 8791 | "GET /x/y/z HTTP/1.1\r\n" |
| 8792 | "Host: www.example.org\r\n" |
| 8793 | "Connection: keep-alive\r\n" |
| 8794 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8795 | }; |
| 8796 | |
| 8797 | // Sever accepts the authorization. |
| 8798 | MockRead data_reads2[] = { |
| 8799 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8800 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8801 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8802 | }; |
| 8803 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8804 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8805 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8806 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8807 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8808 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8809 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8810 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8811 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8812 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8813 | |
| 8814 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8815 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8816 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8817 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8818 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8819 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8820 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8821 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8822 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8823 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8824 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8825 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8826 | |
| 8827 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8828 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8829 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8830 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8831 | ASSERT_TRUE(response); |
| 8832 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8833 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8834 | } |
| 8835 | |
| 8836 | // ------------------------------------------------------------------------ |
| 8837 | |
| 8838 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 8839 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8840 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8841 | request.method = "GET"; |
| 8842 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 8843 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8844 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8845 | request.traffic_annotation = |
| 8846 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8847 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8848 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8849 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8850 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8851 | MockWrite( |
| 8852 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8853 | "Host: www.example.org\r\n" |
| 8854 | "Connection: keep-alive\r\n" |
| 8855 | // Send preemptive authorization for MyRealm1 |
| 8856 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8857 | }; |
| 8858 | |
| 8859 | // The server didn't like the preemptive authorization, and |
| 8860 | // challenges us for a different realm (MyRealm2). |
| 8861 | MockRead data_reads1[] = { |
| 8862 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8863 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 8864 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8865 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8866 | }; |
| 8867 | |
| 8868 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 8869 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8870 | MockWrite( |
| 8871 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8872 | "Host: www.example.org\r\n" |
| 8873 | "Connection: keep-alive\r\n" |
| 8874 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8875 | }; |
| 8876 | |
| 8877 | // Sever accepts the authorization. |
| 8878 | MockRead data_reads2[] = { |
| 8879 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8880 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8881 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8882 | }; |
| 8883 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8884 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8885 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8886 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8887 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8888 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8889 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8890 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8891 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8892 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8893 | |
| 8894 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8895 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8896 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8897 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8898 | ASSERT_TRUE(response); |
| 8899 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8900 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8901 | EXPECT_EQ("http://www.example.org", |
| 8902 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8903 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 8904 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8905 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8906 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8907 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8908 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 8909 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8910 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8911 | |
| 8912 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8913 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8914 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8915 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8916 | ASSERT_TRUE(response); |
| 8917 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8918 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8919 | } |
| 8920 | |
| 8921 | // ------------------------------------------------------------------------ |
| 8922 | |
| 8923 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 8924 | // succeed with preemptive authorization. |
| 8925 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8926 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8927 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8928 | request.url = GURL("http://www.example.org/x/y/z2"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8929 | request.traffic_annotation = |
| 8930 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8931 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8932 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8933 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8934 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8935 | MockWrite( |
| 8936 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 8937 | "Host: www.example.org\r\n" |
| 8938 | "Connection: keep-alive\r\n" |
| 8939 | // The authorization for MyRealm1 gets sent preemptively |
| 8940 | // (since the url is in the same protection space) |
| 8941 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8942 | }; |
| 8943 | |
| 8944 | // Sever accepts the preemptive authorization |
| 8945 | MockRead data_reads1[] = { |
| 8946 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8947 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8948 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8949 | }; |
| 8950 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8951 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8952 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8953 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8954 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8955 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8956 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8957 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8958 | |
| 8959 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8960 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8961 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8962 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8963 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8964 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8965 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8966 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8967 | } |
| 8968 | |
| 8969 | // ------------------------------------------------------------------------ |
| 8970 | |
| 8971 | // Transaction 4: request another URL in MyRealm (however the |
| 8972 | // url is not known to belong to the protection space, so no pre-auth). |
| 8973 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8974 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8975 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8976 | request.url = GURL("http://www.example.org/x/1"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8977 | request.traffic_annotation = |
| 8978 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8979 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8980 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8981 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8982 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8983 | MockWrite( |
| 8984 | "GET /x/1 HTTP/1.1\r\n" |
| 8985 | "Host: www.example.org\r\n" |
| 8986 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8987 | }; |
| 8988 | |
| 8989 | MockRead data_reads1[] = { |
| 8990 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8991 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8992 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8993 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8994 | }; |
| 8995 | |
| 8996 | // Resend with authorization from MyRealm's cache. |
| 8997 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8998 | MockWrite( |
| 8999 | "GET /x/1 HTTP/1.1\r\n" |
| 9000 | "Host: www.example.org\r\n" |
| 9001 | "Connection: keep-alive\r\n" |
| 9002 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9003 | }; |
| 9004 | |
| 9005 | // Sever accepts the authorization. |
| 9006 | MockRead data_reads2[] = { |
| 9007 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9008 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9009 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9010 | }; |
| 9011 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9012 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9013 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9014 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9015 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9016 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9017 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9018 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9019 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9020 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9021 | |
| 9022 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9023 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9024 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9025 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9026 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9027 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9028 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9029 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9030 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9031 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9032 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9033 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9034 | ASSERT_TRUE(response); |
| 9035 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9036 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9037 | } |
| 9038 | |
| 9039 | // ------------------------------------------------------------------------ |
| 9040 | |
| 9041 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 9042 | // cached identity. Should invalidate and re-prompt. |
| 9043 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9044 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9045 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9046 | request.url = GURL("http://www.example.org/p/q/t"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9047 | request.traffic_annotation = |
| 9048 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9049 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9050 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9051 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9052 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9053 | MockWrite( |
| 9054 | "GET /p/q/t HTTP/1.1\r\n" |
| 9055 | "Host: www.example.org\r\n" |
| 9056 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9057 | }; |
| 9058 | |
| 9059 | MockRead data_reads1[] = { |
| 9060 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9061 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9062 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9063 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9064 | }; |
| 9065 | |
| 9066 | // Resend with authorization from cache for MyRealm. |
| 9067 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9068 | MockWrite( |
| 9069 | "GET /p/q/t HTTP/1.1\r\n" |
| 9070 | "Host: www.example.org\r\n" |
| 9071 | "Connection: keep-alive\r\n" |
| 9072 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9073 | }; |
| 9074 | |
| 9075 | // Sever rejects the authorization. |
| 9076 | MockRead data_reads2[] = { |
| 9077 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9078 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9079 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9080 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9081 | }; |
| 9082 | |
| 9083 | // At this point we should prompt for new credentials for MyRealm. |
| 9084 | // Restart with username=foo3, password=foo4. |
| 9085 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9086 | MockWrite( |
| 9087 | "GET /p/q/t HTTP/1.1\r\n" |
| 9088 | "Host: www.example.org\r\n" |
| 9089 | "Connection: keep-alive\r\n" |
| 9090 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9091 | }; |
| 9092 | |
| 9093 | // Sever accepts the authorization. |
| 9094 | MockRead data_reads3[] = { |
| 9095 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9096 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9097 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9098 | }; |
| 9099 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9100 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9101 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 9102 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9103 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9104 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9105 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9106 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9107 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9108 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9109 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9110 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9111 | |
| 9112 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9113 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9114 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9115 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9116 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9117 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9118 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9119 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9120 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9121 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9122 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9123 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9124 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9125 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9126 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9127 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9128 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9129 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 9130 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9131 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9132 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9133 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9134 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9135 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9136 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9137 | ASSERT_TRUE(response); |
| 9138 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9139 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9140 | } |
| 9141 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9142 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9143 | // Tests that nonce count increments when multiple auth attempts |
| 9144 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9145 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 9146 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 9147 | new HttpAuthHandlerDigest::Factory(); |
| 9148 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 9149 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 9150 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9151 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9152 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9153 | |
| 9154 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 9155 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9156 | HttpRequestInfo request; |
| 9157 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9158 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9159 | request.traffic_annotation = |
| 9160 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9161 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9162 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9163 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9164 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9165 | MockWrite( |
| 9166 | "GET /x/y/z HTTP/1.1\r\n" |
| 9167 | "Host: www.example.org\r\n" |
| 9168 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9169 | }; |
| 9170 | |
| 9171 | MockRead data_reads1[] = { |
| 9172 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9173 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 9174 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9175 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9176 | }; |
| 9177 | |
| 9178 | // Resend with authorization (username=foo, password=bar) |
| 9179 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9180 | MockWrite( |
| 9181 | "GET /x/y/z HTTP/1.1\r\n" |
| 9182 | "Host: www.example.org\r\n" |
| 9183 | "Connection: keep-alive\r\n" |
| 9184 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9185 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 9186 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 9187 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9188 | }; |
| 9189 | |
| 9190 | // Sever accepts the authorization. |
| 9191 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9192 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9193 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9194 | }; |
| 9195 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9196 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9197 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9198 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9199 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9200 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9201 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9202 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9203 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9204 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9205 | |
| 9206 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9207 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9208 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9209 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9210 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9211 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9212 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9213 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9214 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9215 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9216 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9217 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9218 | |
| 9219 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9220 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9221 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9222 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9223 | ASSERT_TRUE(response); |
| 9224 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9225 | } |
| 9226 | |
| 9227 | // ------------------------------------------------------------------------ |
| 9228 | |
| 9229 | // Transaction 2: Request another resource in digestive's protection space. |
| 9230 | // This will preemptively add an Authorization header which should have an |
| 9231 | // "nc" value of 2 (as compared to 1 in the first use. |
| 9232 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9233 | HttpRequestInfo request; |
| 9234 | request.method = "GET"; |
| 9235 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 9236 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9237 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9238 | request.traffic_annotation = |
| 9239 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9240 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9241 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9242 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9243 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9244 | MockWrite( |
| 9245 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 9246 | "Host: www.example.org\r\n" |
| 9247 | "Connection: keep-alive\r\n" |
| 9248 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9249 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 9250 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 9251 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9252 | }; |
| 9253 | |
| 9254 | // Sever accepts the authorization. |
| 9255 | MockRead data_reads1[] = { |
| 9256 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9257 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9258 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9259 | }; |
| 9260 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9261 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9262 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9263 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9264 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9265 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9266 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9267 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9268 | |
| 9269 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9270 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9271 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9272 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9273 | ASSERT_TRUE(response); |
| 9274 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9275 | } |
| 9276 | } |
| 9277 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9278 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9279 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9280 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9281 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9282 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9283 | |
| 9284 | // Setup some state (which we expect ResetStateForRestart() will clear). |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 9285 | trans.read_buf_ = base::MakeRefCounted<IOBuffer>(15); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9286 | trans.read_buf_len_ = 15; |
| 9287 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9288 | |
| 9289 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9290 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9291 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9292 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9293 | response->response_time = base::Time::Now(); |
| 9294 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9295 | |
| 9296 | { // Setup state for response_.vary_data |
| 9297 | HttpRequestInfo request; |
| 9298 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 9299 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 9300 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9301 | request.extra_headers.SetHeader("Foo", "1"); |
| 9302 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9303 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9304 | } |
| 9305 | |
| 9306 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9307 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9308 | |
| 9309 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9310 | EXPECT_FALSE(trans.read_buf_); |
| 9311 | EXPECT_EQ(0, trans.read_buf_len_); |
| 9312 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9313 | EXPECT_FALSE(response->auth_challenge); |
| 9314 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 9315 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9316 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9317 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9318 | } |
| 9319 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9320 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9321 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9322 | HttpRequestInfo request; |
| 9323 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9324 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9325 | request.traffic_annotation = |
| 9326 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9327 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9328 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9329 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9330 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9331 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9332 | MockWrite( |
| 9333 | "GET / HTTP/1.1\r\n" |
| 9334 | "Host: www.example.org\r\n" |
| 9335 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9336 | }; |
| 9337 | |
| 9338 | MockRead data_reads[] = { |
| 9339 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9340 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9341 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9342 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9343 | }; |
| 9344 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 9345 | StaticSocketDataProvider ssl_bad_certificate; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9346 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9347 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9348 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9349 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9350 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9351 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9352 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9353 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9354 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9355 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9356 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9357 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9358 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9359 | |
| 9360 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9361 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9362 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9363 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9364 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9365 | |
| 9366 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9367 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9368 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9369 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9370 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9371 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9372 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9373 | } |
| 9374 | |
| 9375 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 9376 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9377 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9378 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9379 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9380 | |
| 9381 | HttpRequestInfo request; |
| 9382 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9383 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9384 | request.traffic_annotation = |
| 9385 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9386 | |
| 9387 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9388 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9389 | "Host: www.example.org:443\r\n" |
| 9390 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9391 | }; |
| 9392 | |
| 9393 | MockRead proxy_reads[] = { |
| 9394 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9395 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9396 | }; |
| 9397 | |
| 9398 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9399 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9400 | "Host: www.example.org:443\r\n" |
| 9401 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9402 | MockWrite("GET / HTTP/1.1\r\n" |
| 9403 | "Host: www.example.org\r\n" |
| 9404 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9405 | }; |
| 9406 | |
| 9407 | MockRead data_reads[] = { |
| 9408 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9409 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9410 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9411 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9412 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9413 | }; |
| 9414 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9415 | StaticSocketDataProvider ssl_bad_certificate(proxy_reads, proxy_writes); |
| 9416 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9417 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9418 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9419 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9420 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9421 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9422 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9423 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9424 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9425 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9426 | |
| 9427 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9428 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9429 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9430 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9431 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9432 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9433 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9434 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9435 | |
| 9436 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9437 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9438 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9439 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9440 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9441 | |
| 9442 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9443 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9444 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9445 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9446 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9447 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9448 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9449 | } |
| 9450 | } |
| 9451 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9452 | |
| 9453 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9454 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9455 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9456 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9457 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9458 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9459 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9460 | |
| 9461 | HttpRequestInfo request; |
| 9462 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9463 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9464 | request.traffic_annotation = |
| 9465 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9466 | |
| 9467 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9468 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9469 | "Host: www.example.org:443\r\n" |
| 9470 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9471 | MockWrite("GET / HTTP/1.1\r\n" |
| 9472 | "Host: www.example.org\r\n" |
| 9473 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9474 | }; |
| 9475 | |
| 9476 | MockRead data_reads[] = { |
| 9477 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9478 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9479 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9480 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9481 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9482 | }; |
| 9483 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9484 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9485 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9486 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9487 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9488 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9489 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9490 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9491 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9492 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9493 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9494 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9495 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9496 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9497 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9498 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9499 | |
| 9500 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9501 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9502 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9503 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9504 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9505 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9506 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9507 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9508 | EXPECT_EQ(200, response->headers->response_code()); |
| 9509 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9510 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9511 | |
| 9512 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9513 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9514 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9515 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9516 | } |
| 9517 | |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9518 | // Test that an HTTPS Proxy can redirect a CONNECT request for main frames. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9519 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9520 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9521 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9522 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9523 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9524 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9525 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9526 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 9527 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 9528 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 9529 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9530 | HttpRequestInfo request; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9531 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9532 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9533 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9534 | request.traffic_annotation = |
| 9535 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9536 | |
| 9537 | MockWrite data_writes[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9538 | MockWrite(ASYNC, 0, |
| 9539 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9540 | "Host: www.example.org:443\r\n" |
| 9541 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9542 | }; |
| 9543 | |
| 9544 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9545 | // Pause on first read. |
| 9546 | MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 9547 | MockRead(ASYNC, 2, "HTTP/1.1 302 Redirect\r\n"), |
| 9548 | MockRead(ASYNC, 3, "Location: http://login.example.com/\r\n"), |
| 9549 | MockRead(ASYNC, 4, "Content-Length: 0\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9550 | }; |
| 9551 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9552 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9553 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9554 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9555 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9556 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9557 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9558 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9559 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9560 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9561 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9562 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9563 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9564 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9565 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
| 9566 | |
| 9567 | // Host resolution takes |kTimeIncrement|. |
| 9568 | FastForwardBy(kTimeIncrement); |
| 9569 | // Resolving the current request with |ResolveNow| will cause the pending |
| 9570 | // request to instantly complete, and the async connect will start as well. |
| 9571 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 9572 | |
| 9573 | // Connecting takes |kTimeIncrement|. |
| 9574 | FastForwardBy(kTimeIncrement); |
| 9575 | data.RunUntilPaused(); |
| 9576 | |
| 9577 | // The server takes |kTimeIncrement| to respond. |
| 9578 | FastForwardBy(kTimeIncrement); |
| 9579 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9580 | |
| 9581 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9582 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9583 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9584 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9585 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9586 | |
| 9587 | EXPECT_EQ(302, response->headers->response_code()); |
| 9588 | std::string url; |
| 9589 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 9590 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9591 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9592 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9593 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9594 | |
| 9595 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 9596 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9597 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9598 | // In the case of redirects from proxies, just as with all responses from |
| 9599 | // proxies, DNS and SSL times reflect timing to look up the destination's |
| 9600 | // name, and negotiate an SSL connection to it (Neither of which are done in |
| 9601 | // this case), which the DNS and SSL times for the proxy are all included in |
| 9602 | // connect_start / connect_end. See |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9603 | // HttpNetworkTransaction::OnHttpsProxyTunnelResponseRedirect |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9604 | |
| 9605 | EXPECT_TRUE(load_timing_info.connect_timing.dns_start.is_null()); |
| 9606 | EXPECT_TRUE(load_timing_info.connect_timing.dns_end.is_null()); |
| 9607 | EXPECT_TRUE(load_timing_info.connect_timing.ssl_start.is_null()); |
| 9608 | EXPECT_TRUE(load_timing_info.connect_timing.ssl_end.is_null()); |
| 9609 | |
| 9610 | EXPECT_EQ(start_time, load_timing_info.proxy_resolve_start); |
| 9611 | EXPECT_EQ(start_time, load_timing_info.proxy_resolve_end); |
| 9612 | EXPECT_EQ(start_time, load_timing_info.connect_timing.connect_start); |
| 9613 | EXPECT_EQ(start_time + 3 * kTimeIncrement, |
| 9614 | load_timing_info.connect_timing.connect_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9615 | |
| 9616 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 9617 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 9618 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9619 | } |
| 9620 | |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9621 | // Test that an HTTPS Proxy cannot redirect a CONNECT request for subresources. |
| 9622 | TEST_F(HttpNetworkTransactionTest, |
| 9623 | RedirectOfHttpsConnectSubresourceViaHttpsProxy) { |
| 9624 | base::HistogramTester histograms; |
| 9625 | session_deps_.proxy_resolution_service = |
| 9626 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9627 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9628 | TestNetLog net_log; |
| 9629 | session_deps_.net_log = &net_log; |
| 9630 | |
| 9631 | HttpRequestInfo request; |
| 9632 | request.method = "GET"; |
| 9633 | request.url = GURL("https://www.example.org/"); |
| 9634 | request.traffic_annotation = |
| 9635 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9636 | |
| 9637 | MockWrite data_writes[] = { |
| 9638 | MockWrite(ASYNC, 0, |
| 9639 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9640 | "Host: www.example.org:443\r\n" |
| 9641 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9642 | }; |
| 9643 | |
| 9644 | MockRead data_reads[] = { |
| 9645 | MockRead(ASYNC, 1, "HTTP/1.1 302 Redirect\r\n"), |
| 9646 | MockRead(ASYNC, 2, "Location: http://login.example.com/\r\n"), |
| 9647 | MockRead(ASYNC, 3, "Content-Length: 0\r\n\r\n"), |
| 9648 | }; |
| 9649 | |
| 9650 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
| 9651 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9652 | |
| 9653 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9654 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9655 | |
| 9656 | TestCompletionCallback callback; |
| 9657 | |
| 9658 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9659 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 9660 | |
| 9661 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 9662 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9663 | |
| 9664 | rv = callback.WaitForResult(); |
| 9665 | EXPECT_THAT(rv, IsError(ERR_HTTPS_PROXY_TUNNEL_RESPONSE_REDIRECT)); |
| 9666 | |
| 9667 | histograms.ExpectUniqueSample( |
| 9668 | "Net.Proxy.RedirectDuringConnect", |
| 9669 | HttpNetworkTransaction::kSubresourceByExplicitProxy, 1); |
| 9670 | } |
| 9671 | |
| 9672 | // Test that an HTTPS Proxy which was auto-detected cannot redirect a CONNECT |
| 9673 | // request for main frames. |
| 9674 | TEST_F(HttpNetworkTransactionTest, |
| 9675 | RedirectOfHttpsConnectViaAutoDetectedHttpsProxy) { |
| 9676 | base::HistogramTester histograms; |
| 9677 | session_deps_.proxy_resolution_service = |
| 9678 | ProxyResolutionService::CreateFixedFromAutoDetectedPacResult( |
| 9679 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9680 | TestNetLog net_log; |
| 9681 | session_deps_.net_log = &net_log; |
| 9682 | |
| 9683 | HttpRequestInfo request; |
| 9684 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
| 9685 | request.method = "GET"; |
| 9686 | request.url = GURL("https://www.example.org/"); |
| 9687 | request.traffic_annotation = |
| 9688 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9689 | |
| 9690 | MockWrite data_writes[] = { |
| 9691 | MockWrite(ASYNC, 0, |
| 9692 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9693 | "Host: www.example.org:443\r\n" |
| 9694 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9695 | }; |
| 9696 | |
| 9697 | MockRead data_reads[] = { |
| 9698 | MockRead(ASYNC, 1, "HTTP/1.1 302 Redirect\r\n"), |
| 9699 | MockRead(ASYNC, 2, "Location: http://login.example.com/\r\n"), |
| 9700 | MockRead(ASYNC, 3, "Content-Length: 0\r\n\r\n"), |
| 9701 | }; |
| 9702 | |
| 9703 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
| 9704 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9705 | |
| 9706 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9707 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9708 | |
| 9709 | TestCompletionCallback callback; |
| 9710 | |
| 9711 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9712 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 9713 | |
| 9714 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 9715 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9716 | |
| 9717 | rv = callback.WaitForResult(); |
| 9718 | EXPECT_THAT(rv, IsError(ERR_HTTPS_PROXY_TUNNEL_RESPONSE_REDIRECT)); |
| 9719 | |
| 9720 | histograms.ExpectUniqueSample( |
| 9721 | "Net.Proxy.RedirectDuringConnect", |
| 9722 | HttpNetworkTransaction::kMainFrameByAutoDetectedProxy, 1); |
| 9723 | } |
| 9724 | |
| 9725 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request for main |
| 9726 | // frames. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9727 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9728 | base::HistogramTester histograms; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9729 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9730 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9731 | TestNetLog net_log; |
| 9732 | session_deps_.net_log = &net_log; |
| 9733 | |
| 9734 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 9735 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 9736 | session_deps_.host_resolver->set_ondemand_mode(true); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9737 | |
| 9738 | HttpRequestInfo request; |
| 9739 | request.method = "GET"; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9740 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9741 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9742 | request.traffic_annotation = |
| 9743 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9744 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9745 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9746 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 9747 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9748 | spdy::SpdySerializedFrame goaway( |
| 9749 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9750 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9751 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9752 | CreateMockWrite(goaway, 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9753 | }; |
| 9754 | |
| 9755 | static const char* const kExtraHeaders[] = { |
| 9756 | "location", |
| 9757 | "http://login.example.com/", |
| 9758 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9759 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9760 | "302", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9761 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9762 | // Pause on first read. |
| 9763 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp, 2), |
| 9764 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9765 | }; |
| 9766 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9767 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9768 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9769 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9770 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9771 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9772 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9773 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9774 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9775 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9776 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9777 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9778 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9779 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9780 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9781 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9782 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9783 | // Host resolution takes |kTimeIncrement|. |
| 9784 | FastForwardBy(kTimeIncrement); |
| 9785 | // Resolving the current request with |ResolveNow| will cause the pending |
| 9786 | // request to instantly complete, and the async connect will start as well. |
| 9787 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 9788 | |
| 9789 | // Connecting takes |kTimeIncrement|. |
| 9790 | FastForwardBy(kTimeIncrement); |
| 9791 | data.RunUntilPaused(); |
| 9792 | |
| 9793 | FastForwardBy(kTimeIncrement); |
| 9794 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9795 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9796 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9797 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9798 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9799 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9800 | |
| 9801 | EXPECT_EQ(302, response->headers->response_code()); |
| 9802 | std::string url; |
| 9803 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 9804 | EXPECT_EQ("http://login.example.com/", url); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9805 | |
| 9806 | LoadTimingInfo load_timing_info; |
| 9807 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 9808 | |
| 9809 | EXPECT_FALSE(load_timing_info.socket_reused); |
| 9810 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
| 9811 | |
| 9812 | // No proxy resolution times, since there's no PAC script. |
| 9813 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 9814 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 9815 | |
| 9816 | // In the case of redirects from proxies, just as with all responses from |
| 9817 | // proxies, DNS and SSL times reflect timing to look up the destination's |
| 9818 | // name, and negotiate an SSL connection to it (Neither of which are done in |
| 9819 | // this case), which the DNS and SSL times for the proxy are all included in |
| 9820 | // connect_start / connect_end. See |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9821 | // HttpNetworkTransaction::OnHttpsProxyTunnelResponseRedirect. |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9822 | |
| 9823 | EXPECT_TRUE(load_timing_info.connect_timing.dns_start.is_null()); |
| 9824 | EXPECT_TRUE(load_timing_info.connect_timing.dns_end.is_null()); |
| 9825 | EXPECT_TRUE(load_timing_info.connect_timing.ssl_start.is_null()); |
| 9826 | EXPECT_TRUE(load_timing_info.connect_timing.ssl_end.is_null()); |
| 9827 | |
| 9828 | EXPECT_EQ(start_time, load_timing_info.connect_timing.connect_start); |
| 9829 | EXPECT_EQ(start_time + 3 * kTimeIncrement, |
| 9830 | load_timing_info.connect_timing.connect_end); |
| 9831 | |
| 9832 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 9833 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 9834 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9835 | |
| 9836 | histograms.ExpectUniqueSample( |
| 9837 | "Net.Proxy.RedirectDuringConnect", |
| 9838 | HttpNetworkTransaction::kMainFrameByExplicitProxy, 1); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9839 | } |
| 9840 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 9841 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9842 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9843 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9844 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9845 | |
| 9846 | HttpRequestInfo request; |
| 9847 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9848 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9849 | request.traffic_annotation = |
| 9850 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9851 | |
| 9852 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9853 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9854 | "Host: www.example.org:443\r\n" |
| 9855 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9856 | }; |
| 9857 | |
| 9858 | MockRead data_reads[] = { |
| 9859 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 9860 | MockRead("Content-Length: 23\r\n\r\n"), |
| 9861 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9862 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9863 | }; |
| 9864 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9865 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9866 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9867 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9868 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9869 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9870 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9871 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9872 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9873 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9874 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9875 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9876 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9877 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9878 | |
| 9879 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9880 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9881 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 9882 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9883 | } |
| 9884 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 9885 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9886 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9887 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9888 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9889 | |
| 9890 | HttpRequestInfo request; |
| 9891 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9892 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9893 | request.traffic_annotation = |
| 9894 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9895 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9896 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9897 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 9898 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9899 | spdy::SpdySerializedFrame rst( |
| 9900 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9901 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9902 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9903 | }; |
| 9904 | |
| 9905 | static const char* const kExtraHeaders[] = { |
| 9906 | "location", |
| 9907 | "http://login.example.com/", |
| 9908 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9909 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9910 | "404", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9911 | spdy::SpdySerializedFrame body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9912 | spdy_util_.ConstructSpdyDataFrame(1, "The host does not exist", true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9913 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9914 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9915 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9916 | }; |
| 9917 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9918 | SequencedSocketData data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9919 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9920 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9921 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9922 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9923 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9924 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9925 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9926 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9927 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9928 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9929 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9930 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9931 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9932 | |
| 9933 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9934 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9935 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 9936 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9937 | } |
| 9938 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9939 | // Test the request-challenge-retry sequence for basic auth, through |
| 9940 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9941 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9942 | HttpRequestInfo request; |
| 9943 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9944 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9945 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 9946 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9947 | request.traffic_annotation = |
| 9948 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9949 | |
| 9950 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9951 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9952 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9953 | "HTTPS myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9954 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9955 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9956 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9957 | |
| 9958 | // Since we have proxy, should try to establish tunnel. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9959 | spdy::SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9960 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 9961 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9962 | spdy::SpdySerializedFrame rst( |
| 9963 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9964 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9965 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9966 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9967 | // be issuing -- the final header line contains the credentials. |
| 9968 | const char* const kAuthCredentials[] = { |
| 9969 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 9970 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9971 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9972 | kAuthCredentials, base::size(kAuthCredentials) / 2, 3, |
| 9973 | HttpProxyConnectJob::kH2QuicTunnelPriority, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9974 | HostPortPair("www.example.org", 443))); |
| 9975 | // fetch https://www.example.org/ via HTTP |
| 9976 | const char get[] = |
| 9977 | "GET / HTTP/1.1\r\n" |
| 9978 | "Host: www.example.org\r\n" |
| 9979 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9980 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9981 | spdy_util_.ConstructSpdyDataFrame(3, get, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9982 | |
| 9983 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9984 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 9985 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9986 | }; |
| 9987 | |
| 9988 | // The proxy responds to the connect with a 407, using a persistent |
| 9989 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 9990 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9991 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9992 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 9993 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9994 | spdy::SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9995 | kAuthStatus, kAuthChallenge, base::size(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9996 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9997 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 9998 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9999 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 10000 | "Content-Length: 5\r\n\r\n"; |
| 10001 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10002 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 10003 | spdy_util_.ConstructSpdyDataFrame(3, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10004 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 10005 | spdy_util_.ConstructSpdyDataFrame(3, "hello", false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10006 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10007 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 10008 | CreateMockRead(conn_resp, 4, ASYNC), |
| 10009 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 10010 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10011 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10012 | }; |
| 10013 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10014 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10015 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10016 | // Negotiate SPDY to the proxy |
| 10017 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10018 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10019 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10020 | // Vanilla SSL to the server |
| 10021 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10022 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10023 | |
| 10024 | TestCompletionCallback callback1; |
| 10025 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10026 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10027 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10028 | |
| 10029 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10030 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10031 | |
| 10032 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10033 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 10034 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10035 | log.GetEntries(&entries); |
| 10036 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 10037 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 10038 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10039 | ExpectLogContainsSomewhere( |
| 10040 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 10041 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 10042 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10043 | |
| 10044 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10045 | ASSERT_TRUE(response); |
| 10046 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10047 | EXPECT_EQ(407, response->headers->response_code()); |
| 10048 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10049 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10050 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10051 | |
| 10052 | TestCompletionCallback callback2; |
| 10053 | |
| 10054 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 10055 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10056 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10057 | |
| 10058 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10059 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10060 | |
| 10061 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10062 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10063 | |
| 10064 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10065 | EXPECT_EQ(200, response->headers->response_code()); |
| 10066 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 10067 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10068 | |
| 10069 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10070 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10071 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10072 | LoadTimingInfo load_timing_info; |
| 10073 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10074 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10075 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10076 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10077 | trans.reset(); |
| 10078 | session->CloseAllConnections(); |
| 10079 | } |
| 10080 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10081 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 10082 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10083 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10084 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10085 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10086 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 10087 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10088 | HttpRequestInfo request; |
| 10089 | HttpRequestInfo push_request; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10090 | request.traffic_annotation = |
| 10091 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10092 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10093 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10094 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10095 | push_request.method = "GET"; |
| 10096 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10097 | push_request.traffic_annotation = |
| 10098 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10099 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10100 | // Configure against https proxy server "myproxy:443". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10101 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10102 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10103 | "HTTPS myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10104 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10105 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10106 | |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10107 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10108 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10109 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10110 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10111 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10112 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10113 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10114 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10115 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10116 | |
| 10117 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10118 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10119 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10120 | }; |
| 10121 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10122 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10123 | nullptr, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 10124 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10125 | spdy::SpdySerializedFrame stream1_reply( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10126 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10127 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10128 | spdy::SpdySerializedFrame stream1_body( |
| 10129 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10130 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10131 | spdy::SpdySerializedFrame stream2_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 10132 | spdy_util_.ConstructSpdyDataFrame(2, "pushed", true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10133 | |
| 10134 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 10135 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 10136 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10137 | CreateMockRead(stream1_body, 4, ASYNC), |
| 10138 | CreateMockRead(stream2_body, 5, ASYNC), |
| 10139 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10140 | }; |
| 10141 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10142 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10143 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10144 | // Negotiate SPDY to the proxy |
| 10145 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10146 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10147 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10148 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10149 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10150 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10151 | TestCompletionCallback callback; |
| 10152 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10153 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10154 | |
| 10155 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10156 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10157 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10158 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10159 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10160 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10161 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10162 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10163 | |
| 10164 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10165 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10166 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 10167 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10168 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10169 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10170 | |
| 10171 | EXPECT_EQ(200, response->headers->response_code()); |
| 10172 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10173 | |
| 10174 | std::string response_data; |
| 10175 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10176 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10177 | EXPECT_EQ("hello!", response_data); |
| 10178 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10179 | LoadTimingInfo load_timing_info; |
| 10180 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10181 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10182 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10183 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10184 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10185 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10186 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 10187 | |
| 10188 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10189 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10190 | EXPECT_EQ("pushed", response_data); |
| 10191 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10192 | LoadTimingInfo push_load_timing_info; |
| 10193 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 10194 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 10195 | // The transactions should share a socket ID, despite being for different |
| 10196 | // origins. |
| 10197 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 10198 | push_load_timing_info.socket_log_id); |
| 10199 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10200 | trans.reset(); |
| 10201 | push_trans.reset(); |
| 10202 | session->CloseAllConnections(); |
| 10203 | } |
| 10204 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10205 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10206 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10207 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10208 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10209 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 10210 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10211 | HttpRequestInfo request; |
| 10212 | |
| 10213 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10214 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10215 | request.traffic_annotation = |
| 10216 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10217 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10218 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10219 | "https://myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10220 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10221 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10222 | |
| 10223 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10224 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10225 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10226 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10227 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10228 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10229 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10230 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10231 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10232 | spdy::SpdySerializedFrame push_rst( |
| 10233 | spdy_util_.ConstructSpdyRstStream(2, spdy::ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10234 | |
| 10235 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10236 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10237 | }; |
| 10238 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10239 | spdy::SpdySerializedFrame stream1_reply( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10240 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10241 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10242 | spdy::SpdySerializedFrame stream1_body( |
| 10243 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10244 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10245 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10246 | nullptr, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10247 | |
| 10248 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10249 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10250 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 10251 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 10252 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10253 | }; |
| 10254 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10255 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10256 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10257 | // Negotiate SPDY to the proxy |
| 10258 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10259 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10260 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10261 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10262 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10263 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10264 | TestCompletionCallback callback; |
| 10265 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10266 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10267 | |
| 10268 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10269 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10270 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10271 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10272 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10273 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10274 | |
| 10275 | EXPECT_EQ(200, response->headers->response_code()); |
| 10276 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10277 | |
| 10278 | std::string response_data; |
| 10279 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10280 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10281 | EXPECT_EQ("hello!", response_data); |
| 10282 | |
| 10283 | trans.reset(); |
| 10284 | session->CloseAllConnections(); |
| 10285 | } |
| 10286 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10287 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 10288 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10289 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10290 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10291 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10292 | proxy_delegate->set_trusted_spdy_proxy( |
| 10293 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 10294 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10295 | HttpRequestInfo request; |
| 10296 | |
| 10297 | request.method = "GET"; |
| 10298 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10299 | request.traffic_annotation = |
| 10300 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10301 | |
| 10302 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10303 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10304 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10305 | BoundTestNetLog log; |
| 10306 | session_deps_.net_log = log.bound().net_log(); |
| 10307 | |
| 10308 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10309 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10310 | proxy_delegate.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10311 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10312 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10313 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10314 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10315 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10316 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10317 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10318 | |
| 10319 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10320 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10321 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10322 | }; |
| 10323 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10324 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10325 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10326 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10327 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 10328 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 10329 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10330 | spdy::SpdySerializedFrame stream1_body( |
| 10331 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10332 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10333 | spdy::SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10334 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10335 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10336 | spdy::SpdySerializedFrame stream2_body( |
| 10337 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10338 | |
| 10339 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10340 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10341 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10342 | CreateMockRead(stream1_body, 4, ASYNC), |
| 10343 | CreateMockRead(stream2_body, 5, ASYNC), |
| 10344 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10345 | }; |
| 10346 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10347 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10348 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 10349 | // Negotiate SPDY to the proxy |
| 10350 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10351 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10352 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 10353 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10354 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10355 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10356 | TestCompletionCallback callback; |
| 10357 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10358 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10359 | |
| 10360 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10361 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10362 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10363 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10364 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10365 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10366 | |
| 10367 | EXPECT_EQ(200, response->headers->response_code()); |
| 10368 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10369 | |
| 10370 | std::string response_data; |
| 10371 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10372 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10373 | EXPECT_EQ("hello!", response_data); |
| 10374 | |
| 10375 | trans.reset(); |
| 10376 | session->CloseAllConnections(); |
| 10377 | } |
| 10378 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10379 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 10380 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10381 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10382 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10383 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10384 | |
| 10385 | HttpRequestInfo request; |
| 10386 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10387 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10388 | request.traffic_annotation = |
| 10389 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10390 | |
| 10391 | // Attempt to fetch the URL from a server with a bad cert |
| 10392 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10393 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10394 | "Host: www.example.org:443\r\n" |
| 10395 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10396 | }; |
| 10397 | |
| 10398 | MockRead bad_cert_reads[] = { |
| 10399 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10400 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10401 | }; |
| 10402 | |
| 10403 | // Attempt to fetch the URL with a good cert |
| 10404 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10405 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10406 | "Host: www.example.org:443\r\n" |
| 10407 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10408 | MockWrite("GET / HTTP/1.1\r\n" |
| 10409 | "Host: www.example.org\r\n" |
| 10410 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10411 | }; |
| 10412 | |
| 10413 | MockRead good_cert_reads[] = { |
| 10414 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 10415 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10416 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10417 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10418 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10419 | }; |
| 10420 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10421 | StaticSocketDataProvider ssl_bad_certificate(bad_cert_reads, bad_cert_writes); |
| 10422 | StaticSocketDataProvider data(good_cert_reads, good_data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10423 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 10424 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10425 | |
| 10426 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10427 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10428 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 10429 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10430 | |
| 10431 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10432 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10433 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10434 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10435 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10436 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10437 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10438 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10439 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10440 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10441 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10442 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10443 | |
| 10444 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10445 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10446 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10447 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10448 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10449 | |
| 10450 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10451 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10452 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10453 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10454 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10455 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10456 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10457 | } |
| 10458 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10459 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10460 | HttpRequestInfo request; |
| 10461 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10462 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10463 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10464 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10465 | request.traffic_annotation = |
| 10466 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10467 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10468 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10469 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10470 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10471 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10472 | MockWrite( |
| 10473 | "GET / HTTP/1.1\r\n" |
| 10474 | "Host: www.example.org\r\n" |
| 10475 | "Connection: keep-alive\r\n" |
| 10476 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10477 | }; |
| 10478 | |
| 10479 | // Lastly, the server responds with the actual content. |
| 10480 | MockRead data_reads[] = { |
| 10481 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10482 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10483 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10484 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10485 | }; |
| 10486 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10487 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10488 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10489 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10490 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10491 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10492 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10493 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10494 | |
| 10495 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10496 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10497 | } |
| 10498 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10499 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10500 | // Test user agent values, used both for the request header of the original |
| 10501 | // request, and the value returned by the HttpUserAgentSettings. nullptr means |
| 10502 | // no request header / no HttpUserAgentSettings object. |
| 10503 | const char* kTestUserAgents[] = {nullptr, "", "Foopy"}; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10504 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10505 | for (const char* setting_user_agent : kTestUserAgents) { |
| 10506 | if (!setting_user_agent) { |
| 10507 | session_deps_.http_user_agent_settings.reset(); |
| 10508 | } else { |
| 10509 | session_deps_.http_user_agent_settings = |
| 10510 | std::make_unique<StaticHttpUserAgentSettings>( |
| 10511 | std::string() /* accept-language */, setting_user_agent); |
| 10512 | } |
| 10513 | session_deps_.proxy_resolution_service = |
| 10514 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 10515 | TRAFFIC_ANNOTATION_FOR_TESTS); |
| 10516 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10517 | for (const char* request_user_agent : kTestUserAgents) { |
| 10518 | HttpRequestInfo request; |
| 10519 | request.method = "GET"; |
| 10520 | request.url = GURL("https://www.example.org/"); |
| 10521 | if (request_user_agent) { |
| 10522 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10523 | request_user_agent); |
| 10524 | } |
| 10525 | request.traffic_annotation = |
| 10526 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10527 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10528 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10529 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10530 | std::string expected_request; |
| 10531 | if (!setting_user_agent || strlen(setting_user_agent) == 0) { |
| 10532 | expected_request = |
| 10533 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10534 | "Host: www.example.org:443\r\n" |
| 10535 | "Proxy-Connection: keep-alive\r\n\r\n"; |
| 10536 | } else { |
| 10537 | expected_request = base::StringPrintf( |
| 10538 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10539 | "Host: www.example.org:443\r\n" |
| 10540 | "Proxy-Connection: keep-alive\r\n" |
| 10541 | "User-Agent: %s\r\n\r\n", |
| 10542 | setting_user_agent); |
| 10543 | } |
| 10544 | MockWrite data_writes[] = { |
| 10545 | MockWrite(expected_request.c_str()), |
| 10546 | }; |
| 10547 | MockRead data_reads[] = { |
| 10548 | // Return an error, so the transaction stops here (this test isn't |
| 10549 | // interested in the rest). |
| 10550 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 10551 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10552 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 10553 | }; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10554 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10555 | StaticSocketDataProvider data(data_reads, data_writes); |
| 10556 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10557 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10558 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10559 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10560 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 10561 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10562 | |
| 10563 | rv = callback.WaitForResult(); |
| 10564 | EXPECT_THAT(rv, IsOk()); |
| 10565 | } |
| 10566 | } |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10567 | } |
| 10568 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10569 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10570 | HttpRequestInfo request; |
| 10571 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10572 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 10573 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 10574 | "http://the.previous.site.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10575 | request.traffic_annotation = |
| 10576 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10577 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10578 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10579 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10580 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10581 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10582 | MockWrite( |
| 10583 | "GET / HTTP/1.1\r\n" |
| 10584 | "Host: www.example.org\r\n" |
| 10585 | "Connection: keep-alive\r\n" |
| 10586 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10587 | }; |
| 10588 | |
| 10589 | // Lastly, the server responds with the actual content. |
| 10590 | MockRead data_reads[] = { |
| 10591 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10592 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10593 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10594 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10595 | }; |
| 10596 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10597 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10598 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10599 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10600 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10601 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10602 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10603 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10604 | |
| 10605 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10606 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10607 | } |
| 10608 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10609 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10610 | HttpRequestInfo request; |
| 10611 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10612 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10613 | request.traffic_annotation = |
| 10614 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10615 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10616 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10617 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10618 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10619 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10620 | MockWrite( |
| 10621 | "POST / HTTP/1.1\r\n" |
| 10622 | "Host: www.example.org\r\n" |
| 10623 | "Connection: keep-alive\r\n" |
| 10624 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10625 | }; |
| 10626 | |
| 10627 | // Lastly, the server responds with the actual content. |
| 10628 | MockRead data_reads[] = { |
| 10629 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10630 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10631 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10632 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10633 | }; |
| 10634 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10635 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10636 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10637 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10638 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10639 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10640 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10641 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10642 | |
| 10643 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10644 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10645 | } |
| 10646 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10647 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10648 | HttpRequestInfo request; |
| 10649 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10650 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10651 | request.traffic_annotation = |
| 10652 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10653 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10654 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10655 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10656 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10657 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10658 | MockWrite( |
| 10659 | "PUT / HTTP/1.1\r\n" |
| 10660 | "Host: www.example.org\r\n" |
| 10661 | "Connection: keep-alive\r\n" |
| 10662 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10663 | }; |
| 10664 | |
| 10665 | // Lastly, the server responds with the actual content. |
| 10666 | MockRead data_reads[] = { |
| 10667 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10668 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10669 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10670 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10671 | }; |
| 10672 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10673 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10674 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10675 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10676 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10677 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10678 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10679 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10680 | |
| 10681 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10682 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10683 | } |
| 10684 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10685 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10686 | HttpRequestInfo request; |
| 10687 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10688 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10689 | request.traffic_annotation = |
| 10690 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10691 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10692 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10693 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10694 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10695 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 10696 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 10697 | "Host: www.example.org\r\n" |
| 10698 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10699 | }; |
| 10700 | |
| 10701 | // Lastly, the server responds with the actual content. |
| 10702 | MockRead data_reads[] = { |
| 10703 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10704 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10705 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10706 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10707 | }; |
| 10708 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10709 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10710 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10711 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10712 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10713 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10714 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10715 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10716 | |
| 10717 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10718 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10719 | } |
| 10720 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10721 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10722 | HttpRequestInfo request; |
| 10723 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10724 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10725 | request.load_flags = LOAD_BYPASS_CACHE; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10726 | request.traffic_annotation = |
| 10727 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10728 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10729 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10730 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10731 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10732 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10733 | MockWrite( |
| 10734 | "GET / HTTP/1.1\r\n" |
| 10735 | "Host: www.example.org\r\n" |
| 10736 | "Connection: keep-alive\r\n" |
| 10737 | "Pragma: no-cache\r\n" |
| 10738 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10739 | }; |
| 10740 | |
| 10741 | // Lastly, the server responds with the actual content. |
| 10742 | MockRead data_reads[] = { |
| 10743 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10744 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10745 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10746 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10747 | }; |
| 10748 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10749 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10750 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10751 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10752 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10753 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10754 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10755 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10756 | |
| 10757 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10758 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10759 | } |
| 10760 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10761 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10762 | HttpRequestInfo request; |
| 10763 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10764 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10765 | request.load_flags = LOAD_VALIDATE_CACHE; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10766 | request.traffic_annotation = |
| 10767 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10768 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10769 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10770 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10771 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10772 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10773 | MockWrite( |
| 10774 | "GET / HTTP/1.1\r\n" |
| 10775 | "Host: www.example.org\r\n" |
| 10776 | "Connection: keep-alive\r\n" |
| 10777 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10778 | }; |
| 10779 | |
| 10780 | // Lastly, the server responds with the actual content. |
| 10781 | MockRead data_reads[] = { |
| 10782 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10783 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10784 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10785 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10786 | }; |
| 10787 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10788 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10789 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10790 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10791 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10792 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10793 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10794 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10795 | |
| 10796 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10797 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10798 | } |
| 10799 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10800 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10801 | HttpRequestInfo request; |
| 10802 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10803 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10804 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10805 | request.traffic_annotation = |
| 10806 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10807 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10808 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10809 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10810 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10811 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10812 | MockWrite( |
| 10813 | "GET / HTTP/1.1\r\n" |
| 10814 | "Host: www.example.org\r\n" |
| 10815 | "Connection: keep-alive\r\n" |
| 10816 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10817 | }; |
| 10818 | |
| 10819 | // Lastly, the server responds with the actual content. |
| 10820 | MockRead data_reads[] = { |
| 10821 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10822 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10823 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10824 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10825 | }; |
| 10826 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10827 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10828 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10829 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10830 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10831 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10832 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10833 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10834 | |
| 10835 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10836 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10837 | } |
| 10838 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10839 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10840 | HttpRequestInfo request; |
| 10841 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10842 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10843 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 10844 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 10845 | request.extra_headers.SetHeader("FoO", "bar"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10846 | request.traffic_annotation = |
| 10847 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10848 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10849 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10850 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10851 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10852 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10853 | MockWrite( |
| 10854 | "GET / HTTP/1.1\r\n" |
| 10855 | "Host: www.example.org\r\n" |
| 10856 | "Connection: keep-alive\r\n" |
| 10857 | "referer: www.foo.com\r\n" |
| 10858 | "hEllo: Kitty\r\n" |
| 10859 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10860 | }; |
| 10861 | |
| 10862 | // Lastly, the server responds with the actual content. |
| 10863 | MockRead data_reads[] = { |
| 10864 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10865 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10866 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10867 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10868 | }; |
| 10869 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10870 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10871 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10872 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10873 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10874 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10875 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10876 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10877 | |
| 10878 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10879 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10880 | } |
| 10881 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10882 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10883 | HttpRequestInfo request; |
| 10884 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10885 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10886 | request.traffic_annotation = |
| 10887 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10888 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10889 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10890 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10891 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10892 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10893 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10894 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10895 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10896 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10897 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10898 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 10899 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10900 | |
| 10901 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10902 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 10903 | MockWrite("GET / HTTP/1.1\r\n" |
| 10904 | "Host: www.example.org\r\n" |
| 10905 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10906 | |
| 10907 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10908 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 10909 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10910 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10911 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10912 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10913 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10914 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10915 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10916 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10917 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10918 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10919 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10920 | |
| 10921 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10922 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10923 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10924 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10925 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10926 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10927 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10928 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10929 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10930 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10931 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10932 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10933 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10934 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10935 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10936 | EXPECT_EQ("Payload", response_text); |
| 10937 | } |
| 10938 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10939 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10940 | HttpRequestInfo request; |
| 10941 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10942 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10943 | request.traffic_annotation = |
| 10944 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10945 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10946 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10947 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10948 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10949 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10950 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10951 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10952 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10953 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10954 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10955 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 10956 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10957 | |
| 10958 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10959 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10960 | base::size(write_buffer)), |
| 10961 | MockWrite("GET / HTTP/1.1\r\n" |
| 10962 | "Host: www.example.org\r\n" |
| 10963 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10964 | |
| 10965 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10966 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 10967 | base::size(read_buffer)), |
| 10968 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10969 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10970 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10971 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10972 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10973 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10974 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10975 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10976 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10977 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10978 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10979 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10980 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10981 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10982 | |
| 10983 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10984 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10985 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10986 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10987 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10988 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10989 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10990 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10991 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10992 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10993 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10994 | |
| 10995 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10996 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10997 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10998 | EXPECT_EQ("Payload", response_text); |
| 10999 | } |
| 11000 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11001 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11002 | HttpRequestInfo request; |
| 11003 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11004 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11005 | request.traffic_annotation = |
| 11006 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11007 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11008 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11009 | "socks4://myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11010 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11011 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11012 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11013 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11014 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11015 | |
| 11016 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 11017 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 11018 | |
| 11019 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11020 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 11021 | MockWrite("GET / HTTP/1.1\r\n" |
| 11022 | "Host: www.example.org\r\n" |
| 11023 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11024 | |
| 11025 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11026 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 11027 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11028 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11029 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11030 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11031 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11032 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11033 | |
| 11034 | TestCompletionCallback callback; |
| 11035 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11036 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11037 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11038 | |
| 11039 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11040 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11041 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11042 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11043 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11044 | |
| 11045 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11046 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11047 | TestLoadTimingNotReused(load_timing_info, |
| 11048 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 11049 | |
| 11050 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11051 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11052 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11053 | EXPECT_EQ("Payload", response_text); |
| 11054 | } |
| 11055 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11056 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11057 | HttpRequestInfo request; |
| 11058 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11059 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11060 | request.traffic_annotation = |
| 11061 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11062 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11063 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11064 | ProxyResolutionService::CreateFixedFromPacResult( |
| 11065 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11066 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11067 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11068 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11069 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11070 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11071 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11072 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 11073 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11074 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11075 | 0x05, // Version |
| 11076 | 0x01, // Command (CONNECT) |
| 11077 | 0x00, // Reserved. |
| 11078 | 0x03, // Address type (DOMAINNAME). |
| 11079 | 0x0F, // Length of domain (15) |
| 11080 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 11081 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11082 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11083 | const char kSOCKS5OkResponse[] = |
| 11084 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 11085 | |
| 11086 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11087 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
| 11088 | MockWrite(ASYNC, kSOCKS5OkRequest, base::size(kSOCKS5OkRequest)), |
| 11089 | MockWrite("GET / HTTP/1.1\r\n" |
| 11090 | "Host: www.example.org\r\n" |
| 11091 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11092 | |
| 11093 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11094 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 11095 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 11096 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11097 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11098 | MockRead("Payload"), |
| 11099 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11100 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11101 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11102 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11103 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11104 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11105 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11106 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11107 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11108 | |
| 11109 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11110 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11111 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11112 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11113 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11114 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11115 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11116 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11117 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11118 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11119 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 11120 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11121 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11122 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11123 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11124 | EXPECT_EQ("Payload", response_text); |
| 11125 | } |
| 11126 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11127 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11128 | HttpRequestInfo request; |
| 11129 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11130 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11131 | request.traffic_annotation = |
| 11132 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11133 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11134 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11135 | ProxyResolutionService::CreateFixedFromPacResult( |
| 11136 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11137 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11138 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11139 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11140 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11141 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11142 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11143 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 11144 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11145 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11146 | 0x05, // Version |
| 11147 | 0x01, // Command (CONNECT) |
| 11148 | 0x00, // Reserved. |
| 11149 | 0x03, // Address type (DOMAINNAME). |
| 11150 | 0x0F, // Length of domain (15) |
| 11151 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 11152 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11153 | }; |
| 11154 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11155 | const char kSOCKS5OkResponse[] = |
| 11156 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 11157 | |
| 11158 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11159 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11160 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11161 | base::size(kSOCKS5OkRequest)), |
| 11162 | MockWrite("GET / HTTP/1.1\r\n" |
| 11163 | "Host: www.example.org\r\n" |
| 11164 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11165 | |
| 11166 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11167 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 11168 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 11169 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11170 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11171 | MockRead("Payload"), |
| 11172 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11173 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11174 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11175 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11176 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11177 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11178 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11179 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11180 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11181 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11182 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11183 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11184 | |
| 11185 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11186 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11187 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11188 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11189 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11190 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11191 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11192 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11193 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11194 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11195 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 11196 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11197 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11198 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11199 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11200 | EXPECT_EQ("Payload", response_text); |
| 11201 | } |
| 11202 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11203 | namespace { |
| 11204 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11205 | // Tests that for connection endpoints the group ids are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11206 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11207 | struct GroupIdTest { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11208 | std::string proxy_server; |
| 11209 | std::string url; |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11210 | ClientSocketPool::GroupId expected_group_id; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 11211 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11212 | }; |
| 11213 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11214 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupIdTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11215 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11216 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11217 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11218 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11219 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11220 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11221 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11222 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 11223 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11224 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11225 | |
| 11226 | return session; |
| 11227 | } |
| 11228 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11229 | int GroupIdTransactionHelper(const std::string& url, |
| 11230 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11231 | HttpRequestInfo request; |
| 11232 | request.method = "GET"; |
| 11233 | request.url = GURL(url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11234 | request.traffic_annotation = |
| 11235 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11236 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11237 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11238 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11239 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11240 | |
| 11241 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11242 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11243 | } |
| 11244 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11245 | } // namespace |
| 11246 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11247 | TEST_F(HttpNetworkTransactionTest, GroupIdForDirectConnections) { |
| 11248 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11249 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11250 | "", // unused |
| 11251 | "http://www.example.org/direct", |
| 11252 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11253 | ClientSocketPool::SocketType::kHttp, |
| 11254 | false /* privacy_mode */), |
| 11255 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11256 | }, |
| 11257 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11258 | "", // unused |
| 11259 | "http://[2001:1418:13:1::25]/direct", |
| 11260 | ClientSocketPool::GroupId(HostPortPair("2001:1418:13:1::25", 80), |
| 11261 | ClientSocketPool::SocketType::kHttp, |
| 11262 | false /* privacy_mode */), |
| 11263 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11264 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11265 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11266 | // SSL Tests |
| 11267 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11268 | "", // unused |
| 11269 | "https://www.example.org/direct_ssl", |
| 11270 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11271 | ClientSocketPool::SocketType::kSsl, |
| 11272 | false /* privacy_mode */), |
| 11273 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11274 | }, |
| 11275 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11276 | "", // unused |
| 11277 | "https://[2001:1418:13:1::25]/direct", |
| 11278 | ClientSocketPool::GroupId(HostPortPair("2001:1418:13:1::25", 443), |
| 11279 | ClientSocketPool::SocketType::kSsl, |
| 11280 | false /* privacy_mode */), |
| 11281 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11282 | }, |
| 11283 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11284 | "", // unused |
| 11285 | "https://host.with.alternate/direct", |
| 11286 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11287 | ClientSocketPool::SocketType::kSsl, |
| 11288 | false /* privacy_mode */), |
| 11289 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11290 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11291 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11292 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11293 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11294 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11295 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11296 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11297 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11298 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11299 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11300 | HttpNetworkSessionPeer peer(session.get()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11301 | CaptureGroupIdTransportSocketPool* transport_conn_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 11302 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11303 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11304 | mock_pool_manager->SetSocketPool(ProxyServer::Direct(), |
| 11305 | base::WrapUnique(transport_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11306 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11307 | |
| 11308 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11309 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11310 | EXPECT_EQ(tests[i].expected_group_id, |
| 11311 | transport_conn_pool->last_group_id_received()); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 11312 | EXPECT_TRUE(transport_conn_pool->socket_requested()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11313 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11314 | } |
| 11315 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11316 | TEST_F(HttpNetworkTransactionTest, GroupIdForHTTPProxyConnections) { |
| 11317 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11318 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11319 | "http_proxy", |
| 11320 | "http://www.example.org/http_proxy_normal", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11321 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11322 | ClientSocketPool::SocketType::kHttp, |
| 11323 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11324 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11325 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11326 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11327 | // SSL Tests |
| 11328 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11329 | "http_proxy", |
| 11330 | "https://www.example.org/http_connect_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11331 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11332 | ClientSocketPool::SocketType::kSsl, |
| 11333 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11334 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11335 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11336 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11337 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11338 | "http_proxy", |
| 11339 | "https://host.with.alternate/direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11340 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11341 | ClientSocketPool::SocketType::kSsl, |
| 11342 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11343 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11344 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 11345 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11346 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11347 | "http_proxy", |
| 11348 | "ftp://ftp.google.com/http_proxy_normal", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11349 | ClientSocketPool::GroupId(HostPortPair("ftp.google.com", 21), |
| 11350 | ClientSocketPool::SocketType::kFtp, |
| 11351 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11352 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11353 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11354 | }; |
| 11355 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11356 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11357 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11358 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11359 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11360 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11361 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11362 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11363 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11364 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11365 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11366 | HostPortPair("http_proxy", 80)); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11367 | CaptureGroupIdTransportSocketPool* http_proxy_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 11368 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11369 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11370 | mock_pool_manager->SetSocketPool(proxy_server, |
| 11371 | base::WrapUnique(http_proxy_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11372 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11373 | |
| 11374 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11375 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11376 | EXPECT_EQ(tests[i].expected_group_id, |
| 11377 | http_proxy_pool->last_group_id_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11378 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11379 | } |
| 11380 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11381 | TEST_F(HttpNetworkTransactionTest, GroupIdForSOCKSConnections) { |
| 11382 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11383 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11384 | "socks4://socks_proxy:1080", |
| 11385 | "http://www.example.org/socks4_direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11386 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11387 | ClientSocketPool::SocketType::kHttp, |
| 11388 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11389 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11390 | }, |
| 11391 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11392 | "socks5://socks_proxy:1080", |
| 11393 | "http://www.example.org/socks5_direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11394 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11395 | ClientSocketPool::SocketType::kHttp, |
| 11396 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11397 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11398 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11399 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11400 | // SSL Tests |
| 11401 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11402 | "socks4://socks_proxy:1080", |
| 11403 | "https://www.example.org/socks4_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11404 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11405 | ClientSocketPool::SocketType::kSsl, |
| 11406 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11407 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11408 | }, |
| 11409 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11410 | "socks5://socks_proxy:1080", |
| 11411 | "https://www.example.org/socks5_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11412 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11413 | ClientSocketPool::SocketType::kSsl, |
| 11414 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11415 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11416 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11417 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11418 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11419 | "socks4://socks_proxy:1080", |
| 11420 | "https://host.with.alternate/direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11421 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11422 | ClientSocketPool::SocketType::kSsl, |
| 11423 | false /* privacy_mode */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11424 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11425 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11426 | }; |
| 11427 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11428 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11429 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11430 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11431 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11432 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11433 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 11434 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11435 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11436 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11437 | ProxyServer proxy_server( |
| 11438 | ProxyServer::FromURI(tests[i].proxy_server, ProxyServer::SCHEME_HTTP)); |
| 11439 | ASSERT_TRUE(proxy_server.is_valid()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11440 | CaptureGroupIdTransportSocketPool* socks_conn_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 11441 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11442 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11443 | mock_pool_manager->SetSocketPool(proxy_server, |
| 11444 | base::WrapUnique(socks_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11445 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11446 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11447 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11448 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11449 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11450 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11451 | EXPECT_EQ(tests[i].expected_group_id, |
| 11452 | socks_conn_pool->last_group_id_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11453 | } |
| 11454 | } |
| 11455 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11456 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11457 | HttpRequestInfo request; |
| 11458 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11459 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11460 | request.traffic_annotation = |
| 11461 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11462 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11463 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11464 | "myproxy:70;foobar:80", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11465 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 11466 | // This simulates failure resolving all hostnames; that means we will fail |
| 11467 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11468 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11469 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11470 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11471 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11472 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11473 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11474 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11475 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11476 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11477 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11478 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11479 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11480 | } |
| 11481 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11482 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11483 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11484 | HttpRequestInfo request; |
| 11485 | request.method = "GET"; |
| 11486 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11487 | request.traffic_annotation = |
| 11488 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11489 | |
| 11490 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11491 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11492 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11493 | StaticSocketDataProvider data(base::span<MockRead>(), write_failure); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11494 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11495 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11496 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11497 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11498 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11499 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11500 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11501 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11502 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11503 | |
| 11504 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11505 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11506 | |
| 11507 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11508 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11509 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11510 | } |
| 11511 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11512 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11513 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11514 | HttpRequestInfo request; |
| 11515 | request.method = "GET"; |
| 11516 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11517 | request.traffic_annotation = |
| 11518 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11519 | |
| 11520 | MockRead data_reads[] = { |
| 11521 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11522 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11523 | }; |
| 11524 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11525 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11526 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11527 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11528 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11529 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11530 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11531 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11532 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11533 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11534 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11535 | |
| 11536 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11537 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11538 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11539 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11540 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11541 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11542 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11543 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11544 | |
| 11545 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11546 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11547 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11548 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11549 | |
| 11550 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11551 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11552 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11553 | } |
| 11554 | |
| 11555 | // Make sure that a dropped connection while draining the body for auth |
| 11556 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11557 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11558 | HttpRequestInfo request; |
| 11559 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11560 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11561 | request.traffic_annotation = |
| 11562 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11563 | |
| 11564 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11565 | MockWrite( |
| 11566 | "GET / HTTP/1.1\r\n" |
| 11567 | "Host: www.example.org\r\n" |
| 11568 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11569 | }; |
| 11570 | |
| 11571 | MockRead data_reads1[] = { |
| 11572 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 11573 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 11574 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11575 | MockRead("Content-Length: 14\r\n\r\n"), |
| 11576 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11577 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11578 | }; |
| 11579 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11580 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11581 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11582 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11583 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11584 | // be issuing -- the final header line contains the credentials. |
| 11585 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11586 | MockWrite( |
| 11587 | "GET / HTTP/1.1\r\n" |
| 11588 | "Host: www.example.org\r\n" |
| 11589 | "Connection: keep-alive\r\n" |
| 11590 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11591 | }; |
| 11592 | |
| 11593 | // Lastly, the server responds with the actual content. |
| 11594 | MockRead data_reads2[] = { |
| 11595 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11596 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11597 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11598 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11599 | }; |
| 11600 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11601 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11602 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11603 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11604 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11605 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11606 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11607 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11608 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11609 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11610 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11611 | |
| 11612 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11613 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11614 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11615 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11616 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11617 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11618 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11619 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11620 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11621 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11622 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11623 | |
| 11624 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11625 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11626 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11627 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11628 | ASSERT_TRUE(response); |
| 11629 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11630 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11631 | } |
| 11632 | |
| 11633 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11634 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11635 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11636 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11637 | |
| 11638 | HttpRequestInfo request; |
| 11639 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11640 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11641 | request.traffic_annotation = |
| 11642 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11643 | |
| 11644 | MockRead proxy_reads[] = { |
| 11645 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11646 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11647 | }; |
| 11648 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11649 | StaticSocketDataProvider data(proxy_reads, base::span<MockWrite>()); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11650 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11651 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11652 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11653 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11654 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11655 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11656 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11657 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11658 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11659 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11660 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11661 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11662 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11663 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11664 | |
| 11665 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11666 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11667 | } |
| 11668 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11669 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11670 | HttpRequestInfo request; |
| 11671 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11672 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11673 | request.traffic_annotation = |
| 11674 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11675 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11676 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11677 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11678 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11679 | MockRead data_reads[] = { |
| 11680 | 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] | 11681 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11682 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11683 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11684 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11685 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11686 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11687 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11688 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11689 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11690 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11691 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11692 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11693 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11694 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11695 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11696 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11697 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11698 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11699 | |
| 11700 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11701 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11702 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11703 | } |
| 11704 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11705 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11706 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11707 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11708 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 11709 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 11710 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11711 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11712 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11713 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11714 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11715 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11716 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11717 | |
| 11718 | HttpRequestInfo request; |
| 11719 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11720 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11721 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11722 | request.traffic_annotation = |
| 11723 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11724 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11725 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11726 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11727 | |
| 11728 | MockRead data_reads[] = { |
| 11729 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 11730 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11731 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11732 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11733 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11734 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11735 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11736 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11737 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11738 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11739 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11740 | |
| 11741 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11742 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11743 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11744 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11745 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11746 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 11747 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11748 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11749 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11750 | } |
| 11751 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11752 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11753 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11754 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11755 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 11756 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 11757 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 11758 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 11759 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11760 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11761 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11762 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11763 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11764 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11765 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11766 | |
| 11767 | HttpRequestInfo request; |
| 11768 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11769 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11770 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11771 | request.traffic_annotation = |
| 11772 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11773 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 11774 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11775 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11776 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11777 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11778 | StaticSocketDataProvider data; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11779 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11780 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11781 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11782 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11783 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11784 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11785 | |
| 11786 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11787 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11788 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11789 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11790 | } |
| 11791 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11792 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11793 | class FakeUploadElementReader : public UploadElementReader { |
| 11794 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 11795 | FakeUploadElementReader() = default; |
| 11796 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11797 | |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11798 | CompletionOnceCallback TakeCallback() { return std::move(callback_); } |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11799 | |
| 11800 | // UploadElementReader overrides: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11801 | int Init(CompletionOnceCallback callback) override { |
| 11802 | callback_ = std::move(callback); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11803 | return ERR_IO_PENDING; |
| 11804 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11805 | uint64_t GetContentLength() const override { return 0; } |
| 11806 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11807 | int Read(IOBuffer* buf, |
| 11808 | int buf_length, |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11809 | CompletionOnceCallback callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11810 | return ERR_FAILED; |
| 11811 | } |
| 11812 | |
| 11813 | private: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11814 | CompletionOnceCallback callback_; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11815 | }; |
| 11816 | |
| 11817 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11818 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 11819 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11820 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11821 | |
| 11822 | HttpRequestInfo request; |
| 11823 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11824 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11825 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11826 | request.traffic_annotation = |
| 11827 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11828 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11829 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11830 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11831 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11832 | |
| 11833 | StaticSocketDataProvider data; |
| 11834 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11835 | |
| 11836 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11837 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11838 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 11839 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11840 | |
| 11841 | // Transaction is pending on request body initialization. |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11842 | CompletionOnceCallback init_callback = fake_reader->TakeCallback(); |
| 11843 | ASSERT_FALSE(init_callback.is_null()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11844 | |
| 11845 | // Return Init()'s result after the transaction gets destroyed. |
| 11846 | trans.reset(); |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11847 | std::move(init_callback).Run(OK); // Should not crash. |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11848 | } |
| 11849 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11850 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11851 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11852 | HttpRequestInfo request; |
| 11853 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11854 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11855 | request.traffic_annotation = |
| 11856 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11857 | |
| 11858 | // First transaction will request a resource and receive a Basic challenge |
| 11859 | // with realm="first_realm". |
| 11860 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11861 | MockWrite( |
| 11862 | "GET / HTTP/1.1\r\n" |
| 11863 | "Host: www.example.org\r\n" |
| 11864 | "Connection: keep-alive\r\n" |
| 11865 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11866 | }; |
| 11867 | MockRead data_reads1[] = { |
| 11868 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11869 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 11870 | "\r\n"), |
| 11871 | }; |
| 11872 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11873 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11874 | // for first_realm. The server will reject and provide a challenge with |
| 11875 | // second_realm. |
| 11876 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11877 | MockWrite( |
| 11878 | "GET / HTTP/1.1\r\n" |
| 11879 | "Host: www.example.org\r\n" |
| 11880 | "Connection: keep-alive\r\n" |
| 11881 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 11882 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11883 | }; |
| 11884 | MockRead data_reads2[] = { |
| 11885 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11886 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 11887 | "\r\n"), |
| 11888 | }; |
| 11889 | |
| 11890 | // This again fails, and goes back to first_realm. Make sure that the |
| 11891 | // entry is removed from cache. |
| 11892 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11893 | MockWrite( |
| 11894 | "GET / HTTP/1.1\r\n" |
| 11895 | "Host: www.example.org\r\n" |
| 11896 | "Connection: keep-alive\r\n" |
| 11897 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 11898 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11899 | }; |
| 11900 | MockRead data_reads3[] = { |
| 11901 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11902 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 11903 | "\r\n"), |
| 11904 | }; |
| 11905 | |
| 11906 | // Try one last time (with the correct password) and get the resource. |
| 11907 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11908 | MockWrite( |
| 11909 | "GET / HTTP/1.1\r\n" |
| 11910 | "Host: www.example.org\r\n" |
| 11911 | "Connection: keep-alive\r\n" |
| 11912 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 11913 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11914 | }; |
| 11915 | MockRead data_reads4[] = { |
| 11916 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11917 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11918 | "Content-Length: 5\r\n" |
| 11919 | "\r\n" |
| 11920 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11921 | }; |
| 11922 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11923 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 11924 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 11925 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
| 11926 | StaticSocketDataProvider data4(data_reads4, data_writes4); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11927 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 11928 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 11929 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 11930 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11931 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11932 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11933 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11934 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11935 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11936 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11937 | // Issue the first request with Authorize headers. There should be a |
| 11938 | // password prompt for first_realm waiting to be filled in after the |
| 11939 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11940 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11941 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11942 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11943 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11944 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11945 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11946 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11947 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11948 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11949 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11950 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11951 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11952 | |
| 11953 | // Issue the second request with an incorrect password. There should be a |
| 11954 | // password prompt for second_realm waiting to be filled in after the |
| 11955 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11956 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11957 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 11958 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11959 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11960 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11961 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11962 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11963 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11964 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11965 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11966 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11967 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11968 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11969 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11970 | |
| 11971 | // Issue the third request with another incorrect password. There should be |
| 11972 | // a password prompt for first_realm waiting to be filled in. If the password |
| 11973 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 11974 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11975 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11976 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 11977 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11978 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11979 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11980 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11981 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11982 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11983 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11984 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11985 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11986 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11987 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11988 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11989 | |
| 11990 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11991 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11992 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 11993 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11994 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11995 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11996 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11997 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11998 | ASSERT_TRUE(response); |
| 11999 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12000 | } |
| 12001 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12002 | // Regression test for https://crbug.com/754395. |
| 12003 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 12004 | MockRead data_reads[] = { |
| 12005 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12006 | MockRead(kAlternativeServiceHttpHeader), |
| 12007 | MockRead("\r\n"), |
| 12008 | MockRead("hello world"), |
| 12009 | MockRead(SYNCHRONOUS, OK), |
| 12010 | }; |
| 12011 | |
| 12012 | HttpRequestInfo request; |
| 12013 | request.method = "GET"; |
| 12014 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12015 | request.traffic_annotation = |
| 12016 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12017 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12018 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12019 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12020 | |
| 12021 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12022 | ssl.ssl_info.cert = |
| 12023 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12024 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 12025 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12026 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12027 | |
| 12028 | TestCompletionCallback callback; |
| 12029 | |
| 12030 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12031 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12032 | |
| 12033 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 12034 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12035 | |
| 12036 | url::SchemeHostPort test_server(request.url); |
| 12037 | HttpServerProperties* http_server_properties = |
| 12038 | session->http_server_properties(); |
| 12039 | EXPECT_TRUE( |
| 12040 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 12041 | |
| 12042 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 12043 | |
| 12044 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 12045 | ASSERT_TRUE(response); |
| 12046 | ASSERT_TRUE(response->headers); |
| 12047 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12048 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 12049 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 12050 | |
| 12051 | std::string response_data; |
| 12052 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 12053 | EXPECT_EQ("hello world", response_data); |
| 12054 | |
| 12055 | EXPECT_TRUE( |
| 12056 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 12057 | } |
| 12058 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12059 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12060 | MockRead data_reads[] = { |
| 12061 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12062 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12063 | MockRead("\r\n"), |
| 12064 | MockRead("hello world"), |
| 12065 | MockRead(SYNCHRONOUS, OK), |
| 12066 | }; |
| 12067 | |
| 12068 | HttpRequestInfo request; |
| 12069 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12070 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12071 | request.traffic_annotation = |
| 12072 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12073 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12074 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12075 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12076 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12077 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12078 | ssl.ssl_info.cert = |
| 12079 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12080 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12081 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12082 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12083 | TestCompletionCallback callback; |
| 12084 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12085 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12086 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12087 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12088 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12089 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12090 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12091 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12092 | HttpServerProperties* http_server_properties = |
| 12093 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12094 | EXPECT_TRUE( |
| 12095 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12096 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12097 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12098 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12099 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12100 | ASSERT_TRUE(response); |
| 12101 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12102 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12103 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12104 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12105 | |
| 12106 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12107 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12108 | EXPECT_EQ("hello world", response_data); |
| 12109 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12110 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 12111 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 12112 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 12113 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 12114 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12115 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12116 | } |
| 12117 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12118 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12119 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12120 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12121 | MockRead data_reads[] = { |
| 12122 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12123 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12124 | MockRead("\r\n"), |
| 12125 | MockRead("hello world"), |
| 12126 | MockRead(SYNCHRONOUS, OK), |
| 12127 | }; |
| 12128 | |
| 12129 | HttpRequestInfo request; |
| 12130 | request.method = "GET"; |
| 12131 | request.url = GURL("http://www.example.org/"); |
| 12132 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12133 | request.traffic_annotation = |
| 12134 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12135 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12136 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12137 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12138 | |
| 12139 | TestCompletionCallback callback; |
| 12140 | |
| 12141 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12142 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12143 | |
| 12144 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12145 | HttpServerProperties* http_server_properties = |
| 12146 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12147 | EXPECT_TRUE( |
| 12148 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12149 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12150 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12151 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12152 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12153 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12154 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12155 | ASSERT_TRUE(response); |
| 12156 | ASSERT_TRUE(response->headers); |
| 12157 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12158 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12159 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12160 | |
| 12161 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12162 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12163 | EXPECT_EQ("hello world", response_data); |
| 12164 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12165 | EXPECT_TRUE( |
| 12166 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12167 | } |
| 12168 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 12169 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12170 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12171 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12172 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 12173 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12174 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12175 | HttpRequestInfo request; |
| 12176 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12177 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12178 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12179 | request.traffic_annotation = |
| 12180 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12181 | |
| 12182 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12183 | StaticSocketDataProvider first_data; |
| 12184 | first_data.set_connect_data(mock_connect); |
| 12185 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12186 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12187 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12188 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12189 | |
| 12190 | MockRead data_reads[] = { |
| 12191 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12192 | MockRead(ASYNC, OK), |
| 12193 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12194 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12195 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12196 | |
| 12197 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12198 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12199 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12200 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12201 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 12202 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12203 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12204 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12205 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 12206 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12207 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12208 | TestCompletionCallback callback; |
| 12209 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12210 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12211 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12212 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12213 | } |
| 12214 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12215 | // Regression test for https://crbug.com/615497: |
| 12216 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12217 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12218 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12219 | HttpRequestInfo request; |
| 12220 | request.method = "GET"; |
| 12221 | request.url = GURL("http://www.example.org/"); |
| 12222 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12223 | request.traffic_annotation = |
| 12224 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12225 | |
| 12226 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12227 | StaticSocketDataProvider first_data; |
| 12228 | first_data.set_connect_data(mock_connect); |
| 12229 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 12230 | |
| 12231 | MockRead data_reads[] = { |
| 12232 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12233 | MockRead(ASYNC, OK), |
| 12234 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12235 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12236 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12237 | |
| 12238 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12239 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12240 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12241 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12242 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12243 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12244 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12245 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 12246 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12247 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12248 | TestCompletionCallback callback; |
| 12249 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12250 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12251 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12252 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12253 | } |
| 12254 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12255 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12256 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12257 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12258 | HttpServerProperties* http_server_properties = |
| 12259 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12260 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12261 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12262 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12263 | http_server_properties->SetQuicAlternativeService( |
| 12264 | test_server, alternative_service, expiration, |
| 12265 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12266 | EXPECT_EQ( |
| 12267 | 1u, |
| 12268 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12269 | |
| 12270 | // Send a clear header. |
| 12271 | MockRead data_reads[] = { |
| 12272 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12273 | MockRead("Alt-Svc: clear\r\n"), |
| 12274 | MockRead("\r\n"), |
| 12275 | MockRead("hello world"), |
| 12276 | MockRead(SYNCHRONOUS, OK), |
| 12277 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12278 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12279 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12280 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12281 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12282 | ssl.ssl_info.cert = |
| 12283 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12284 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12285 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12286 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12287 | HttpRequestInfo request; |
| 12288 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12289 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12290 | request.traffic_annotation = |
| 12291 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12292 | |
| 12293 | TestCompletionCallback callback; |
| 12294 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12295 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12296 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12297 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12298 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12299 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12300 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12301 | ASSERT_TRUE(response); |
| 12302 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12303 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12304 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12305 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12306 | |
| 12307 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12308 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12309 | EXPECT_EQ("hello world", response_data); |
| 12310 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12311 | EXPECT_TRUE( |
| 12312 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12313 | } |
| 12314 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12315 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12316 | MockRead data_reads[] = { |
| 12317 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12318 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 12319 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12320 | MockRead("hello world"), |
| 12321 | MockRead(SYNCHRONOUS, OK), |
| 12322 | }; |
| 12323 | |
| 12324 | HttpRequestInfo request; |
| 12325 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12326 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12327 | request.traffic_annotation = |
| 12328 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12329 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12330 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12331 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12332 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12333 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12334 | ssl.ssl_info.cert = |
| 12335 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12336 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12337 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12338 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12339 | TestCompletionCallback callback; |
| 12340 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12341 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12342 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12343 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12344 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12345 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12346 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12347 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12348 | HttpServerProperties* http_server_properties = |
| 12349 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12350 | EXPECT_TRUE( |
| 12351 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12352 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12353 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12354 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12355 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12356 | ASSERT_TRUE(response); |
| 12357 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12358 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12359 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12360 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12361 | |
| 12362 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12363 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12364 | EXPECT_EQ("hello world", response_data); |
| 12365 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12366 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 12367 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 12368 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 12369 | |
| 12370 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 12371 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12372 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12373 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 12374 | 1234); |
| 12375 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12376 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12377 | } |
| 12378 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12379 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12380 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12381 | HostPortPair alternative("alternative.example.org", 443); |
| 12382 | std::string origin_url = "https://origin.example.org:443"; |
| 12383 | std::string alternative_url = "https://alternative.example.org:443"; |
| 12384 | |
| 12385 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12386 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12387 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12388 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12389 | |
| 12390 | // HTTP/1.1 data for request. |
| 12391 | MockWrite http_writes[] = { |
| 12392 | MockWrite("GET / HTTP/1.1\r\n" |
| 12393 | "Host: alternative.example.org\r\n" |
| 12394 | "Connection: keep-alive\r\n\r\n"), |
| 12395 | }; |
| 12396 | |
| 12397 | MockRead http_reads[] = { |
| 12398 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12399 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12400 | "Content-Length: 40\r\n\r\n" |
| 12401 | "first HTTP/1.1 response from alternative"), |
| 12402 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12403 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12404 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12405 | |
| 12406 | StaticSocketDataProvider data_refused; |
| 12407 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12408 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12409 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12410 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12411 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12412 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12413 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12414 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12415 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12416 | http_server_properties->SetQuicAlternativeService( |
| 12417 | server, alternative_service, expiration, |
| 12418 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12419 | // Mark the QUIC alternative service as broken. |
| 12420 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 12421 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12422 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12423 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12424 | request.method = "GET"; |
| 12425 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12426 | request.traffic_annotation = |
| 12427 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12428 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12429 | TestCompletionCallback callback; |
| 12430 | NetErrorDetails details; |
| 12431 | EXPECT_FALSE(details.quic_broken); |
| 12432 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12433 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12434 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12435 | EXPECT_TRUE(details.quic_broken); |
| 12436 | } |
| 12437 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12438 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12439 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12440 | HostPortPair alternative1("alternative1.example.org", 443); |
| 12441 | HostPortPair alternative2("alternative2.example.org", 443); |
| 12442 | std::string origin_url = "https://origin.example.org:443"; |
| 12443 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 12444 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 12445 | |
| 12446 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 12447 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12448 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12449 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12450 | |
| 12451 | // HTTP/1.1 data for request. |
| 12452 | MockWrite http_writes[] = { |
| 12453 | MockWrite("GET / HTTP/1.1\r\n" |
| 12454 | "Host: alternative1.example.org\r\n" |
| 12455 | "Connection: keep-alive\r\n\r\n"), |
| 12456 | }; |
| 12457 | |
| 12458 | MockRead http_reads[] = { |
| 12459 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12460 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12461 | "Content-Length: 40\r\n\r\n" |
| 12462 | "first HTTP/1.1 response from alternative1"), |
| 12463 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12464 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12465 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12466 | |
| 12467 | StaticSocketDataProvider data_refused; |
| 12468 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12469 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12470 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12471 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12472 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12473 | session->http_server_properties(); |
| 12474 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12475 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12476 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 12477 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 12478 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12479 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12480 | alternative_service_info_vector.push_back( |
| 12481 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12482 | alternative_service1, expiration, |
| 12483 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12484 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12485 | alternative_service_info_vector.push_back( |
| 12486 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12487 | alternative_service2, expiration, |
| 12488 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12489 | |
| 12490 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12491 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12492 | |
| 12493 | // Mark one of the QUIC alternative service as broken. |
| 12494 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12495 | EXPECT_EQ(2u, |
| 12496 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12497 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12498 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12499 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12500 | request.method = "GET"; |
| 12501 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12502 | request.traffic_annotation = |
| 12503 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12504 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12505 | TestCompletionCallback callback; |
| 12506 | NetErrorDetails details; |
| 12507 | EXPECT_FALSE(details.quic_broken); |
| 12508 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12509 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12510 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12511 | EXPECT_FALSE(details.quic_broken); |
| 12512 | } |
| 12513 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12514 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12515 | HttpRequestInfo request; |
| 12516 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12517 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12518 | request.traffic_annotation = |
| 12519 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12520 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12521 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12522 | StaticSocketDataProvider first_data; |
| 12523 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12524 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12525 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12526 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12527 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12528 | |
| 12529 | MockRead data_reads[] = { |
| 12530 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12531 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12532 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12533 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12534 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12535 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12536 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12537 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12538 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12539 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12540 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12541 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12542 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 12543 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12544 | // Port is ignored by MockConnect anyway. |
| 12545 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12546 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12547 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12548 | http_server_properties->SetHttp2AlternativeService( |
| 12549 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12550 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12551 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12552 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12553 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12554 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12555 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12556 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12557 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12558 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12559 | ASSERT_TRUE(response); |
| 12560 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12561 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12562 | |
| 12563 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12564 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12565 | EXPECT_EQ("hello world", response_data); |
| 12566 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12567 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 12568 | http_server_properties->GetAlternativeServiceInfos(server); |
| 12569 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 12570 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12571 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12572 | EXPECT_TRUE( |
| 12573 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12574 | } |
| 12575 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12576 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12577 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12578 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12579 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12580 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12581 | HttpRequestInfo restricted_port_request; |
| 12582 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12583 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12584 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12585 | restricted_port_request.traffic_annotation = |
| 12586 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12587 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12588 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12589 | StaticSocketDataProvider first_data; |
| 12590 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12591 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12592 | |
| 12593 | MockRead data_reads[] = { |
| 12594 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12595 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12596 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12597 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12598 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12599 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12600 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12601 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12602 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12603 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12604 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12605 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12606 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12607 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12608 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12609 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12610 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12611 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12612 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12613 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12614 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12615 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12616 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12617 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12618 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12619 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12620 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12621 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12622 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12623 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12624 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12625 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12626 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 12627 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 12628 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12629 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12630 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12631 | |
| 12632 | HttpRequestInfo restricted_port_request; |
| 12633 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12634 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12635 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12636 | restricted_port_request.traffic_annotation = |
| 12637 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12638 | |
| 12639 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12640 | StaticSocketDataProvider first_data; |
| 12641 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12642 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12643 | |
| 12644 | MockRead data_reads[] = { |
| 12645 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12646 | MockRead("hello world"), |
| 12647 | MockRead(ASYNC, OK), |
| 12648 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12649 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12650 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12651 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12652 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12653 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12654 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12655 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12656 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12657 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12658 | session->http_server_properties(); |
| 12659 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12660 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12661 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12662 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12663 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12664 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12665 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12666 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12667 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12668 | TestCompletionCallback callback; |
| 12669 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12670 | EXPECT_EQ(ERR_IO_PENDING, |
| 12671 | trans.Start(&restricted_port_request, callback.callback(), |
| 12672 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12673 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12674 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12675 | } |
| 12676 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12677 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12678 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12679 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12680 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12681 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12682 | HttpRequestInfo restricted_port_request; |
| 12683 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12684 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12685 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12686 | restricted_port_request.traffic_annotation = |
| 12687 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12688 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12689 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12690 | StaticSocketDataProvider first_data; |
| 12691 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12692 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12693 | |
| 12694 | MockRead data_reads[] = { |
| 12695 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12696 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12697 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12698 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12699 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12700 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12701 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12702 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12703 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12704 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12705 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12706 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12707 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12708 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12709 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12710 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12711 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12712 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12713 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12714 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12715 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12716 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12717 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12718 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12719 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12720 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12721 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12722 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12723 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12724 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12725 | } |
| 12726 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12727 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12728 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12729 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12730 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12731 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12732 | HttpRequestInfo unrestricted_port_request; |
| 12733 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12734 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12735 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12736 | unrestricted_port_request.traffic_annotation = |
| 12737 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12738 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12739 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12740 | StaticSocketDataProvider first_data; |
| 12741 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12742 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12743 | |
| 12744 | MockRead data_reads[] = { |
| 12745 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12746 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12747 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12748 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12749 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12750 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12751 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12752 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12753 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12754 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12755 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12756 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12757 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12758 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12759 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12760 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12761 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12762 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12763 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12764 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12765 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12766 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12767 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12768 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12769 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12770 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12771 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12772 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12773 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12774 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12775 | } |
| 12776 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12777 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12778 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12779 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12780 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12781 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12782 | HttpRequestInfo unrestricted_port_request; |
| 12783 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12784 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12785 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12786 | unrestricted_port_request.traffic_annotation = |
| 12787 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12788 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12789 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12790 | StaticSocketDataProvider first_data; |
| 12791 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12792 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12793 | |
| 12794 | MockRead data_reads[] = { |
| 12795 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12796 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12797 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12798 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12799 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12800 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12801 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12802 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12803 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12804 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12805 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12806 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12807 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12808 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 12809 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12810 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12811 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12812 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12813 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12814 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12815 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12816 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12817 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12818 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12819 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12820 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12821 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12822 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12823 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12824 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12825 | } |
| 12826 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12827 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
Xida Chen | 9bfe0b6 | 2018-04-24 19:52:21 | [diff] [blame] | 12828 | // to an unsafe port, and that we resume the second HttpStreamFactory::Job once |
| 12829 | // the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12830 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12831 | HttpRequestInfo request; |
| 12832 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12833 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12834 | request.traffic_annotation = |
| 12835 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12836 | |
| 12837 | // The alternate protocol request will error out before we attempt to connect, |
| 12838 | // so only the standard HTTP request will try to connect. |
| 12839 | MockRead data_reads[] = { |
| 12840 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12841 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12842 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12843 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12844 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12845 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12846 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12847 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12848 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12849 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12850 | session->http_server_properties(); |
| 12851 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12852 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12853 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12854 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12855 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12856 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12857 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12858 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12859 | TestCompletionCallback callback; |
| 12860 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12861 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12862 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12863 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12864 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12865 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12866 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12867 | ASSERT_TRUE(response); |
| 12868 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12869 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12870 | |
| 12871 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12872 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12873 | EXPECT_EQ("hello world", response_data); |
| 12874 | } |
| 12875 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12876 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12877 | HttpRequestInfo request; |
| 12878 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12879 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12880 | request.traffic_annotation = |
| 12881 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12882 | |
| 12883 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12884 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12885 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12886 | MockRead("\r\n"), |
| 12887 | MockRead("hello world"), |
| 12888 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12889 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12890 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12891 | StaticSocketDataProvider first_transaction(data_reads, |
| 12892 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12893 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12894 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12895 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12896 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12897 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12898 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12899 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12900 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12901 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12902 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12903 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 12904 | spdy::SpdySerializedFrame resp( |
| 12905 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12906 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12907 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12908 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12909 | }; |
| 12910 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12911 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12912 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12913 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12914 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12915 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12916 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 12917 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12918 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12919 | &hanging_non_alternate_protocol_socket); |
| 12920 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12921 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12922 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12923 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12924 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12925 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12926 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12927 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12928 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12929 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12930 | |
| 12931 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12932 | ASSERT_TRUE(response); |
| 12933 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12934 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12935 | |
| 12936 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12937 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12938 | EXPECT_EQ("hello world", response_data); |
| 12939 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12940 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12941 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12942 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12943 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12944 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12945 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12946 | |
| 12947 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12948 | ASSERT_TRUE(response); |
| 12949 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12950 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12951 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12952 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12953 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12954 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12955 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12956 | } |
| 12957 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12958 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12959 | HttpRequestInfo request; |
| 12960 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12961 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12962 | request.traffic_annotation = |
| 12963 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12964 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12965 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12966 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12967 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12968 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12969 | MockRead("\r\n"), |
| 12970 | MockRead("hello world"), |
| 12971 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12972 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12973 | }; |
| 12974 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12975 | StaticSocketDataProvider http11_data(data_reads, base::span<MockWrite>()); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12976 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12977 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12978 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12979 | ssl_http11.ssl_info.cert = |
| 12980 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12981 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12982 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 12983 | |
| 12984 | // Second transaction starts an alternative and a non-alternative Job. |
| 12985 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12986 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12987 | StaticSocketDataProvider hanging_socket1; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12988 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12989 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 12990 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12991 | StaticSocketDataProvider hanging_socket2; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12992 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 12993 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12994 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12995 | // Third transaction starts an alternative and a non-alternative job. |
| 12996 | // The non-alternative job hangs, but the alternative one succeeds. |
| 12997 | // The second transaction, still pending, binds to this socket. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12998 | spdy::SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12999 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13000 | spdy::SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13001 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13002 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13003 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13004 | }; |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13005 | spdy::SpdySerializedFrame resp1( |
| 13006 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13007 | spdy::SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13008 | spdy::SpdySerializedFrame resp2( |
| 13009 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13010 | spdy::SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13011 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13012 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 13013 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13014 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13015 | }; |
| 13016 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13017 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13018 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13019 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13020 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13021 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13022 | StaticSocketDataProvider hanging_socket3; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13023 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 13024 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13025 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13026 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13027 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13028 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13029 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13030 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13031 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13032 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13033 | |
| 13034 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13035 | ASSERT_TRUE(response); |
| 13036 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13037 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13038 | |
| 13039 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13040 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13041 | EXPECT_EQ("hello world", response_data); |
| 13042 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13043 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13044 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13045 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13046 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13047 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13048 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13049 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13050 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13051 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13052 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13053 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 13054 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13055 | |
| 13056 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13057 | ASSERT_TRUE(response); |
| 13058 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13059 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13060 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13061 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13062 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13063 | EXPECT_EQ("hello!", response_data); |
| 13064 | |
| 13065 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13066 | ASSERT_TRUE(response); |
| 13067 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13068 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13069 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13070 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13071 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13072 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13073 | } |
| 13074 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13075 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
Bence Béky | bcae3709 | 2018-06-12 04:18:53 | [diff] [blame] | 13076 | session_deps_.host_resolver->set_synchronous_mode(true); |
| 13077 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13078 | HttpRequestInfo request; |
| 13079 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13080 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13081 | request.traffic_annotation = |
| 13082 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13083 | |
| 13084 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13085 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13086 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13087 | MockRead("\r\n"), |
| 13088 | MockRead("hello world"), |
| 13089 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13090 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13091 | }; |
| 13092 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13093 | StaticSocketDataProvider first_transaction(data_reads, |
| 13094 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13095 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13096 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13097 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 13098 | ssl.ssl_info.cert = |
| 13099 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 13100 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13101 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13102 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13103 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13104 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13105 | hanging_alternate_protocol_socket.set_connect_data( |
| 13106 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13107 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13108 | &hanging_alternate_protocol_socket); |
| 13109 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13110 | // 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] | 13111 | StaticSocketDataProvider second_transaction(data_reads, |
| 13112 | base::span<MockWrite>()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13113 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13114 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13115 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13116 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13117 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13118 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13119 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13120 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13121 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13122 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13123 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13124 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13125 | |
| 13126 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13127 | ASSERT_TRUE(response); |
| 13128 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13129 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13130 | |
| 13131 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13132 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13133 | EXPECT_EQ("hello world", response_data); |
| 13134 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13135 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13136 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13137 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13138 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13139 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13140 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13141 | |
| 13142 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13143 | ASSERT_TRUE(response); |
| 13144 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13145 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13146 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13147 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13148 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13149 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13150 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13151 | } |
| 13152 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13153 | // Test that proxy is resolved using the origin url, |
| 13154 | // regardless of the alternative server. |
| 13155 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 13156 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 13157 | ProxyConfig proxy_config; |
| 13158 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 13159 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13160 | auto proxy_config_service = std::make_unique<ProxyConfigServiceFixed>( |
| 13161 | ProxyConfigWithAnnotation(proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13162 | |
| 13163 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13164 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13165 | &capturing_proxy_resolver); |
| 13166 | |
| 13167 | TestNetLog net_log; |
| 13168 | |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 13169 | session_deps_.proxy_resolution_service = |
| 13170 | std::make_unique<ProxyResolutionService>( |
| 13171 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 13172 | &net_log); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13173 | |
| 13174 | session_deps_.net_log = &net_log; |
| 13175 | |
| 13176 | // Configure alternative service with a hostname that is not bypassed by the |
| 13177 | // proxy. |
| 13178 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13179 | HttpServerProperties* http_server_properties = |
| 13180 | session->http_server_properties(); |
| 13181 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13182 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13183 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13184 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13185 | http_server_properties->SetHttp2AlternativeService( |
| 13186 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13187 | |
| 13188 | // Non-alternative job should hang. |
| 13189 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13190 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13191 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 13192 | session_deps_.socket_factory->AddSocketDataProvider( |
| 13193 | &hanging_alternate_protocol_socket); |
| 13194 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13195 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13196 | |
| 13197 | HttpRequestInfo request; |
| 13198 | request.method = "GET"; |
| 13199 | request.url = GURL("https://www.example.org/"); |
| 13200 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13201 | request.traffic_annotation = |
| 13202 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13203 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13204 | spdy::SpdySerializedFrame req( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13205 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 13206 | |
| 13207 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 13208 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13209 | spdy::SpdySerializedFrame resp( |
| 13210 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13211 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13212 | MockRead spdy_reads[] = { |
| 13213 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 13214 | }; |
| 13215 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13216 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13217 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 13218 | |
| 13219 | TestCompletionCallback callback; |
| 13220 | |
| 13221 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13222 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13223 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13224 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 13225 | |
| 13226 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 13227 | ASSERT_TRUE(response); |
| 13228 | ASSERT_TRUE(response->headers); |
| 13229 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13230 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13231 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13232 | |
| 13233 | std::string response_data; |
| 13234 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 13235 | EXPECT_EQ("hello!", response_data); |
| 13236 | |
| 13237 | // Origin host bypasses proxy, no resolution should have happened. |
| 13238 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 13239 | } |
| 13240 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13241 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13242 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13243 | proxy_config.set_auto_detect(true); |
| 13244 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 13245 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13246 | CapturingProxyResolver capturing_proxy_resolver; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13247 | session_deps_.proxy_resolution_service = |
| 13248 | std::make_unique<ProxyResolutionService>( |
| 13249 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 13250 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 13251 | std::make_unique<CapturingProxyResolverFactory>( |
| 13252 | &capturing_proxy_resolver), |
| 13253 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13254 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13255 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13256 | |
| 13257 | HttpRequestInfo request; |
| 13258 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13259 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13260 | request.traffic_annotation = |
| 13261 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13262 | |
| 13263 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13264 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13265 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13266 | MockRead("\r\n"), |
| 13267 | MockRead("hello world"), |
| 13268 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13269 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13270 | }; |
| 13271 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13272 | StaticSocketDataProvider first_transaction(data_reads, |
| 13273 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13274 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13275 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13276 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13277 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13278 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13279 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13280 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13281 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13282 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13283 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13284 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13285 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13286 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13287 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13288 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13289 | }; |
| 13290 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13291 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 13292 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13293 | spdy::SpdySerializedFrame resp( |
| 13294 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13295 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13296 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13297 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 13298 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13299 | }; |
| 13300 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13301 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13302 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13303 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13304 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13305 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13306 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 13307 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13308 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13309 | &hanging_non_alternate_protocol_socket); |
| 13310 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13311 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13312 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13313 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13314 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13315 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13316 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13317 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13318 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13319 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 13320 | |
| 13321 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13322 | ASSERT_TRUE(response); |
| 13323 | ASSERT_TRUE(response->headers); |
| 13324 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 13325 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13326 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13327 | |
| 13328 | std::string response_data; |
| 13329 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 13330 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13331 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13332 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13333 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13334 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13335 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13336 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13337 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13338 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13339 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13340 | ASSERT_TRUE(response); |
| 13341 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13342 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13343 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13344 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13345 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13346 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13347 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13348 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 13349 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13350 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13351 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13352 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13353 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13354 | LoadTimingInfo load_timing_info; |
| 13355 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 13356 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13357 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13358 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13359 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13360 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 13361 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13362 | HttpRequestInfo request; |
| 13363 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13364 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13365 | request.traffic_annotation = |
| 13366 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13367 | |
| 13368 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13369 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13370 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13371 | MockRead("\r\n"), |
| 13372 | MockRead("hello world"), |
| 13373 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13374 | }; |
| 13375 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13376 | StaticSocketDataProvider first_transaction(data_reads, |
| 13377 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13378 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13379 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13380 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13381 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13382 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13383 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13384 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13385 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13386 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13387 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13388 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13389 | spdy::SpdySerializedFrame resp( |
| 13390 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13391 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13392 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13393 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13394 | }; |
| 13395 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13396 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13397 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13398 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 13399 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13400 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13401 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13402 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13403 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13404 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13405 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13406 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13407 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13408 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13409 | |
| 13410 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13411 | ASSERT_TRUE(response); |
| 13412 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13413 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13414 | |
| 13415 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13416 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13417 | EXPECT_EQ("hello world", response_data); |
| 13418 | |
| 13419 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13420 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13421 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 13422 | PRIVACY_MODE_DISABLED, |
| 13423 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13424 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 13425 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 13426 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13427 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13428 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13429 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13430 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13431 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13432 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13433 | |
| 13434 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13435 | ASSERT_TRUE(response); |
| 13436 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13437 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13438 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13439 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13440 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13441 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13442 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13443 | } |
| 13444 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13445 | // GenerateAuthToken is a mighty big test. |
| 13446 | // It tests all permutation of GenerateAuthToken behavior: |
| 13447 | // - Synchronous and Asynchronous completion. |
| 13448 | // - OK or error on completion. |
| 13449 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 13450 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 13451 | // - Non-authenticating and authenticating backend. |
| 13452 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 13453 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13454 | // problems generating an auth token for an authenticating proxy, we don't |
| 13455 | // need to test all permutations of the backend server). |
| 13456 | // |
| 13457 | // The test proceeds by going over each of the configuration cases, and |
| 13458 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 13459 | // specifies both the configuration for the test as well as the expectations |
| 13460 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13461 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13462 | static const char kServer[] = "http://www.example.com"; |
| 13463 | static const char kSecureServer[] = "https://www.example.com"; |
| 13464 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13465 | |
| 13466 | enum AuthTiming { |
| 13467 | AUTH_NONE, |
| 13468 | AUTH_SYNC, |
| 13469 | AUTH_ASYNC, |
| 13470 | }; |
| 13471 | |
| 13472 | const MockWrite kGet( |
| 13473 | "GET / HTTP/1.1\r\n" |
| 13474 | "Host: www.example.com\r\n" |
| 13475 | "Connection: keep-alive\r\n\r\n"); |
| 13476 | const MockWrite kGetProxy( |
| 13477 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13478 | "Host: www.example.com\r\n" |
| 13479 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13480 | const MockWrite kGetAuth( |
| 13481 | "GET / HTTP/1.1\r\n" |
| 13482 | "Host: www.example.com\r\n" |
| 13483 | "Connection: keep-alive\r\n" |
| 13484 | "Authorization: auth_token\r\n\r\n"); |
| 13485 | const MockWrite kGetProxyAuth( |
| 13486 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13487 | "Host: www.example.com\r\n" |
| 13488 | "Proxy-Connection: keep-alive\r\n" |
| 13489 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13490 | const MockWrite kGetAuthThroughProxy( |
| 13491 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13492 | "Host: www.example.com\r\n" |
| 13493 | "Proxy-Connection: keep-alive\r\n" |
| 13494 | "Authorization: auth_token\r\n\r\n"); |
| 13495 | const MockWrite kGetAuthWithProxyAuth( |
| 13496 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13497 | "Host: www.example.com\r\n" |
| 13498 | "Proxy-Connection: keep-alive\r\n" |
| 13499 | "Proxy-Authorization: auth_token\r\n" |
| 13500 | "Authorization: auth_token\r\n\r\n"); |
| 13501 | const MockWrite kConnect( |
| 13502 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13503 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13504 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13505 | const MockWrite kConnectProxyAuth( |
| 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" |
| 13509 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13510 | |
| 13511 | const MockRead kSuccess( |
| 13512 | "HTTP/1.1 200 OK\r\n" |
| 13513 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13514 | "Content-Length: 3\r\n\r\n" |
| 13515 | "Yes"); |
| 13516 | const MockRead kFailure( |
| 13517 | "Should not be called."); |
| 13518 | const MockRead kServerChallenge( |
| 13519 | "HTTP/1.1 401 Unauthorized\r\n" |
| 13520 | "WWW-Authenticate: Mock realm=server\r\n" |
| 13521 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13522 | "Content-Length: 14\r\n\r\n" |
| 13523 | "Unauthorized\r\n"); |
| 13524 | const MockRead kProxyChallenge( |
| 13525 | "HTTP/1.1 407 Unauthorized\r\n" |
| 13526 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 13527 | "Proxy-Connection: close\r\n" |
| 13528 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13529 | "Content-Length: 14\r\n\r\n" |
| 13530 | "Unauthorized\r\n"); |
| 13531 | const MockRead kProxyConnected( |
| 13532 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 13533 | |
| 13534 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 13535 | // no constructors, but the C++ compiler on Windows warns about |
| 13536 | // unspecified data in compound literals. So, moved to using constructors, |
| 13537 | // and TestRound's created with the default constructor should not be used. |
| 13538 | struct TestRound { |
| 13539 | TestRound() |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13540 | : expected_rv(ERR_UNEXPECTED), |
| 13541 | extra_write(nullptr), |
| 13542 | extra_read(nullptr) {} |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 13543 | TestRound(const MockWrite& write_arg, |
| 13544 | const MockRead& read_arg, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13545 | int expected_rv_arg) |
| 13546 | : write(write_arg), |
| 13547 | read(read_arg), |
| 13548 | expected_rv(expected_rv_arg), |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13549 | extra_write(nullptr), |
| 13550 | extra_read(nullptr) {} |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13551 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 13552 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 13553 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13554 | : write(write_arg), |
| 13555 | read(read_arg), |
| 13556 | expected_rv(expected_rv_arg), |
| 13557 | extra_write(extra_write_arg), |
| 13558 | extra_read(extra_read_arg) { |
| 13559 | } |
| 13560 | MockWrite write; |
| 13561 | MockRead read; |
| 13562 | int expected_rv; |
| 13563 | const MockWrite* extra_write; |
| 13564 | const MockRead* extra_read; |
| 13565 | }; |
| 13566 | |
| 13567 | static const int kNoSSL = 500; |
| 13568 | |
| 13569 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13570 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13571 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13572 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13573 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13574 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13575 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13576 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13577 | int num_auth_rounds; |
| 13578 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13579 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13580 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13581 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13582 | {__LINE__, |
| 13583 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13584 | AUTH_NONE, |
| 13585 | OK, |
| 13586 | kServer, |
| 13587 | AUTH_NONE, |
| 13588 | OK, |
| 13589 | 1, |
| 13590 | kNoSSL, |
| 13591 | {TestRound(kGet, kSuccess, OK)}}, |
| 13592 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13593 | {__LINE__, |
| 13594 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13595 | AUTH_NONE, |
| 13596 | OK, |
| 13597 | kServer, |
| 13598 | AUTH_SYNC, |
| 13599 | OK, |
| 13600 | 2, |
| 13601 | kNoSSL, |
| 13602 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13603 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13604 | {__LINE__, |
| 13605 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13606 | AUTH_NONE, |
| 13607 | OK, |
| 13608 | kServer, |
| 13609 | AUTH_SYNC, |
| 13610 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13611 | 3, |
| 13612 | kNoSSL, |
| 13613 | {TestRound(kGet, kServerChallenge, OK), |
| 13614 | TestRound(kGet, kServerChallenge, OK), |
| 13615 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13616 | {__LINE__, |
| 13617 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13618 | AUTH_NONE, |
| 13619 | OK, |
| 13620 | kServer, |
| 13621 | AUTH_SYNC, |
| 13622 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 13623 | 2, |
| 13624 | kNoSSL, |
| 13625 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13626 | {__LINE__, |
| 13627 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13628 | AUTH_NONE, |
| 13629 | OK, |
| 13630 | kServer, |
| 13631 | AUTH_SYNC, |
| 13632 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 13633 | 2, |
| 13634 | kNoSSL, |
| 13635 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13636 | {__LINE__, |
| 13637 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13638 | AUTH_SYNC, |
| 13639 | ERR_FAILED, |
| 13640 | kServer, |
| 13641 | AUTH_NONE, |
| 13642 | OK, |
| 13643 | 2, |
| 13644 | kNoSSL, |
| 13645 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13646 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13647 | {__LINE__, |
| 13648 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13649 | AUTH_ASYNC, |
| 13650 | ERR_FAILED, |
| 13651 | kServer, |
| 13652 | AUTH_NONE, |
| 13653 | OK, |
| 13654 | 2, |
| 13655 | kNoSSL, |
| 13656 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13657 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13658 | {__LINE__, |
| 13659 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13660 | AUTH_NONE, |
| 13661 | OK, |
| 13662 | kServer, |
| 13663 | AUTH_SYNC, |
| 13664 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13665 | 2, |
| 13666 | kNoSSL, |
| 13667 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13668 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13669 | {__LINE__, |
| 13670 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13671 | AUTH_NONE, |
| 13672 | OK, |
| 13673 | kServer, |
| 13674 | AUTH_ASYNC, |
| 13675 | ERR_FAILED, |
| 13676 | 2, |
| 13677 | kNoSSL, |
| 13678 | {TestRound(kGet, kServerChallenge, OK), |
| 13679 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13680 | {__LINE__, |
| 13681 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13682 | AUTH_NONE, |
| 13683 | OK, |
| 13684 | kServer, |
| 13685 | AUTH_ASYNC, |
| 13686 | OK, |
| 13687 | 2, |
| 13688 | kNoSSL, |
| 13689 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13690 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13691 | {__LINE__, |
| 13692 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13693 | AUTH_NONE, |
| 13694 | OK, |
| 13695 | kServer, |
| 13696 | AUTH_ASYNC, |
| 13697 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13698 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13699 | kNoSSL, |
| 13700 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13701 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 13702 | TestRound(kGet, kServerChallenge, OK), |
| 13703 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13704 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13705 | {__LINE__, |
| 13706 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13707 | AUTH_NONE, |
| 13708 | OK, |
| 13709 | kServer, |
| 13710 | AUTH_NONE, |
| 13711 | OK, |
| 13712 | 1, |
| 13713 | kNoSSL, |
| 13714 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 13715 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13716 | {__LINE__, |
| 13717 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13718 | AUTH_NONE, |
| 13719 | OK, |
| 13720 | kServer, |
| 13721 | AUTH_SYNC, |
| 13722 | OK, |
| 13723 | 2, |
| 13724 | kNoSSL, |
| 13725 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13726 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13727 | {__LINE__, |
| 13728 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13729 | AUTH_NONE, |
| 13730 | OK, |
| 13731 | kServer, |
| 13732 | AUTH_SYNC, |
| 13733 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13734 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13735 | kNoSSL, |
| 13736 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13737 | TestRound(kGetProxy, kServerChallenge, OK), |
| 13738 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13739 | {__LINE__, |
| 13740 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13741 | AUTH_NONE, |
| 13742 | OK, |
| 13743 | kServer, |
| 13744 | AUTH_ASYNC, |
| 13745 | OK, |
| 13746 | 2, |
| 13747 | kNoSSL, |
| 13748 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13749 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13750 | {__LINE__, |
| 13751 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13752 | AUTH_NONE, |
| 13753 | OK, |
| 13754 | kServer, |
| 13755 | AUTH_ASYNC, |
| 13756 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13757 | 2, |
| 13758 | kNoSSL, |
| 13759 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13760 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13761 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13762 | {__LINE__, |
| 13763 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13764 | AUTH_SYNC, |
| 13765 | OK, |
| 13766 | kServer, |
| 13767 | AUTH_NONE, |
| 13768 | OK, |
| 13769 | 2, |
| 13770 | kNoSSL, |
| 13771 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13772 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13773 | {__LINE__, |
| 13774 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13775 | AUTH_SYNC, |
| 13776 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13777 | kServer, |
| 13778 | AUTH_NONE, |
| 13779 | OK, |
| 13780 | 2, |
| 13781 | kNoSSL, |
| 13782 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13783 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13784 | {__LINE__, |
| 13785 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13786 | AUTH_ASYNC, |
| 13787 | OK, |
| 13788 | kServer, |
| 13789 | AUTH_NONE, |
| 13790 | OK, |
| 13791 | 2, |
| 13792 | kNoSSL, |
| 13793 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13794 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13795 | {__LINE__, |
| 13796 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13797 | AUTH_ASYNC, |
| 13798 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13799 | kServer, |
| 13800 | AUTH_NONE, |
| 13801 | OK, |
| 13802 | 2, |
| 13803 | kNoSSL, |
| 13804 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13805 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13806 | {__LINE__, |
| 13807 | kProxy, |
| 13808 | AUTH_ASYNC, |
| 13809 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13810 | kServer, |
| 13811 | AUTH_NONE, |
| 13812 | OK, |
| 13813 | 3, |
| 13814 | kNoSSL, |
| 13815 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13816 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13817 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13818 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13819 | {__LINE__, |
| 13820 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13821 | AUTH_SYNC, |
| 13822 | OK, |
| 13823 | kServer, |
| 13824 | AUTH_SYNC, |
| 13825 | OK, |
| 13826 | 3, |
| 13827 | kNoSSL, |
| 13828 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13829 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13830 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13831 | {__LINE__, |
| 13832 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13833 | AUTH_SYNC, |
| 13834 | OK, |
| 13835 | kServer, |
| 13836 | AUTH_SYNC, |
| 13837 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13838 | 3, |
| 13839 | kNoSSL, |
| 13840 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13841 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13842 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13843 | {__LINE__, |
| 13844 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13845 | AUTH_ASYNC, |
| 13846 | OK, |
| 13847 | kServer, |
| 13848 | AUTH_SYNC, |
| 13849 | OK, |
| 13850 | 3, |
| 13851 | kNoSSL, |
| 13852 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13853 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13854 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13855 | {__LINE__, |
| 13856 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13857 | AUTH_ASYNC, |
| 13858 | OK, |
| 13859 | kServer, |
| 13860 | AUTH_SYNC, |
| 13861 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13862 | 3, |
| 13863 | kNoSSL, |
| 13864 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13865 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13866 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13867 | {__LINE__, |
| 13868 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13869 | AUTH_SYNC, |
| 13870 | OK, |
| 13871 | kServer, |
| 13872 | AUTH_ASYNC, |
| 13873 | OK, |
| 13874 | 3, |
| 13875 | kNoSSL, |
| 13876 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13877 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13878 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13879 | {__LINE__, |
| 13880 | kProxy, |
| 13881 | AUTH_SYNC, |
| 13882 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13883 | kServer, |
| 13884 | AUTH_ASYNC, |
| 13885 | OK, |
| 13886 | 4, |
| 13887 | kNoSSL, |
| 13888 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13889 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13890 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13891 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 13892 | {__LINE__, |
| 13893 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13894 | AUTH_SYNC, |
| 13895 | OK, |
| 13896 | kServer, |
| 13897 | AUTH_ASYNC, |
| 13898 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13899 | 3, |
| 13900 | kNoSSL, |
| 13901 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13902 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13903 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13904 | {__LINE__, |
| 13905 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13906 | AUTH_ASYNC, |
| 13907 | OK, |
| 13908 | kServer, |
| 13909 | AUTH_ASYNC, |
| 13910 | OK, |
| 13911 | 3, |
| 13912 | kNoSSL, |
| 13913 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13914 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13915 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13916 | {__LINE__, |
| 13917 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13918 | AUTH_ASYNC, |
| 13919 | OK, |
| 13920 | kServer, |
| 13921 | AUTH_ASYNC, |
| 13922 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13923 | 3, |
| 13924 | kNoSSL, |
| 13925 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13926 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13927 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13928 | {__LINE__, |
| 13929 | kProxy, |
| 13930 | AUTH_ASYNC, |
| 13931 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13932 | kServer, |
| 13933 | AUTH_ASYNC, |
| 13934 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13935 | 4, |
| 13936 | kNoSSL, |
| 13937 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13938 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13939 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13940 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13941 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13942 | {__LINE__, |
| 13943 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13944 | AUTH_NONE, |
| 13945 | OK, |
| 13946 | kSecureServer, |
| 13947 | AUTH_NONE, |
| 13948 | OK, |
| 13949 | 1, |
| 13950 | 0, |
| 13951 | {TestRound(kGet, kSuccess, OK)}}, |
| 13952 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13953 | {__LINE__, |
| 13954 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13955 | AUTH_NONE, |
| 13956 | OK, |
| 13957 | kSecureServer, |
| 13958 | AUTH_SYNC, |
| 13959 | OK, |
| 13960 | 2, |
| 13961 | 0, |
| 13962 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13963 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13964 | {__LINE__, |
| 13965 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13966 | AUTH_NONE, |
| 13967 | OK, |
| 13968 | kSecureServer, |
| 13969 | AUTH_SYNC, |
| 13970 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13971 | 2, |
| 13972 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13973 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13974 | {__LINE__, |
| 13975 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13976 | AUTH_NONE, |
| 13977 | OK, |
| 13978 | kSecureServer, |
| 13979 | AUTH_ASYNC, |
| 13980 | OK, |
| 13981 | 2, |
| 13982 | 0, |
| 13983 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13984 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13985 | {__LINE__, |
| 13986 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13987 | AUTH_NONE, |
| 13988 | OK, |
| 13989 | kSecureServer, |
| 13990 | AUTH_ASYNC, |
| 13991 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13992 | 2, |
| 13993 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13994 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13995 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13996 | {__LINE__, |
| 13997 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13998 | AUTH_NONE, |
| 13999 | OK, |
| 14000 | kSecureServer, |
| 14001 | AUTH_NONE, |
| 14002 | OK, |
| 14003 | 1, |
| 14004 | 0, |
| 14005 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 14006 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14007 | {__LINE__, |
| 14008 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14009 | AUTH_NONE, |
| 14010 | OK, |
| 14011 | kSecureServer, |
| 14012 | AUTH_SYNC, |
| 14013 | OK, |
| 14014 | 2, |
| 14015 | 0, |
| 14016 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14017 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14018 | {__LINE__, |
| 14019 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14020 | AUTH_NONE, |
| 14021 | OK, |
| 14022 | kSecureServer, |
| 14023 | AUTH_SYNC, |
| 14024 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14025 | 2, |
| 14026 | 0, |
| 14027 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14028 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14029 | {__LINE__, |
| 14030 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14031 | AUTH_NONE, |
| 14032 | OK, |
| 14033 | kSecureServer, |
| 14034 | AUTH_ASYNC, |
| 14035 | OK, |
| 14036 | 2, |
| 14037 | 0, |
| 14038 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14039 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14040 | {__LINE__, |
| 14041 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14042 | AUTH_NONE, |
| 14043 | OK, |
| 14044 | kSecureServer, |
| 14045 | AUTH_ASYNC, |
| 14046 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14047 | 2, |
| 14048 | 0, |
| 14049 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14050 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14051 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14052 | {__LINE__, |
| 14053 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14054 | AUTH_SYNC, |
| 14055 | OK, |
| 14056 | kSecureServer, |
| 14057 | AUTH_NONE, |
| 14058 | OK, |
| 14059 | 2, |
| 14060 | 1, |
| 14061 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14062 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14063 | {__LINE__, |
| 14064 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14065 | AUTH_SYNC, |
| 14066 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14067 | kSecureServer, |
| 14068 | AUTH_NONE, |
| 14069 | OK, |
| 14070 | 2, |
| 14071 | kNoSSL, |
| 14072 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14073 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14074 | {__LINE__, |
| 14075 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14076 | AUTH_SYNC, |
| 14077 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 14078 | kSecureServer, |
| 14079 | AUTH_NONE, |
| 14080 | OK, |
| 14081 | 2, |
| 14082 | kNoSSL, |
| 14083 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14084 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14085 | {__LINE__, |
| 14086 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14087 | AUTH_SYNC, |
| 14088 | ERR_UNEXPECTED, |
| 14089 | kSecureServer, |
| 14090 | AUTH_NONE, |
| 14091 | OK, |
| 14092 | 2, |
| 14093 | kNoSSL, |
| 14094 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14095 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14096 | {__LINE__, |
| 14097 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14098 | AUTH_ASYNC, |
| 14099 | OK, |
| 14100 | kSecureServer, |
| 14101 | AUTH_NONE, |
| 14102 | OK, |
| 14103 | 2, |
| 14104 | 1, |
| 14105 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14106 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14107 | {__LINE__, |
| 14108 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14109 | AUTH_ASYNC, |
| 14110 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14111 | kSecureServer, |
| 14112 | AUTH_NONE, |
| 14113 | OK, |
| 14114 | 2, |
| 14115 | kNoSSL, |
| 14116 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14117 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14118 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14119 | {__LINE__, |
| 14120 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14121 | AUTH_SYNC, |
| 14122 | OK, |
| 14123 | kSecureServer, |
| 14124 | AUTH_SYNC, |
| 14125 | OK, |
| 14126 | 3, |
| 14127 | 1, |
| 14128 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14129 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14130 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14131 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14132 | {__LINE__, |
| 14133 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14134 | AUTH_SYNC, |
| 14135 | OK, |
| 14136 | kSecureServer, |
| 14137 | AUTH_SYNC, |
| 14138 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14139 | 3, |
| 14140 | 1, |
| 14141 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14142 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14143 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14144 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14145 | {__LINE__, |
| 14146 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14147 | AUTH_ASYNC, |
| 14148 | OK, |
| 14149 | kSecureServer, |
| 14150 | AUTH_SYNC, |
| 14151 | OK, |
| 14152 | 3, |
| 14153 | 1, |
| 14154 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14155 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14156 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14157 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14158 | {__LINE__, |
| 14159 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14160 | AUTH_ASYNC, |
| 14161 | OK, |
| 14162 | kSecureServer, |
| 14163 | AUTH_SYNC, |
| 14164 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14165 | 3, |
| 14166 | 1, |
| 14167 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14168 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14169 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14170 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14171 | {__LINE__, |
| 14172 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14173 | AUTH_SYNC, |
| 14174 | OK, |
| 14175 | kSecureServer, |
| 14176 | AUTH_ASYNC, |
| 14177 | OK, |
| 14178 | 3, |
| 14179 | 1, |
| 14180 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14181 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14182 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14183 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14184 | {__LINE__, |
| 14185 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14186 | AUTH_SYNC, |
| 14187 | OK, |
| 14188 | kSecureServer, |
| 14189 | AUTH_ASYNC, |
| 14190 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14191 | 3, |
| 14192 | 1, |
| 14193 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14194 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14195 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14196 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14197 | {__LINE__, |
| 14198 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14199 | AUTH_ASYNC, |
| 14200 | OK, |
| 14201 | kSecureServer, |
| 14202 | AUTH_ASYNC, |
| 14203 | OK, |
| 14204 | 3, |
| 14205 | 1, |
| 14206 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14207 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14208 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14209 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14210 | {__LINE__, |
| 14211 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14212 | AUTH_ASYNC, |
| 14213 | OK, |
| 14214 | kSecureServer, |
| 14215 | AUTH_ASYNC, |
| 14216 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14217 | 3, |
| 14218 | 1, |
| 14219 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14220 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14221 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14222 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14223 | {__LINE__, |
| 14224 | kProxy, |
| 14225 | AUTH_ASYNC, |
| 14226 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14227 | kSecureServer, |
| 14228 | AUTH_ASYNC, |
| 14229 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14230 | 4, |
| 14231 | 2, |
| 14232 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14233 | TestRound(kConnect, kProxyChallenge, OK), |
| 14234 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14235 | &kServerChallenge), |
| 14236 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14237 | }; |
| 14238 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14239 | for (const auto& test_config : test_configs) { |
| 14240 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 14241 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14242 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14243 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14244 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14245 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14246 | |
| 14247 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14248 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14249 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14250 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14251 | std::string auth_challenge = "Mock realm=proxy"; |
| 14252 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14253 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14254 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14255 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14256 | empty_ssl_info, origin, |
| 14257 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14258 | auth_handler->SetGenerateExpectation( |
| 14259 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14260 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14261 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 14262 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14263 | } |
| 14264 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 14265 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14266 | std::string auth_challenge = "Mock realm=server"; |
| 14267 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14268 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14269 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14270 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14271 | empty_ssl_info, origin, |
| 14272 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14273 | auth_handler->SetGenerateExpectation( |
| 14274 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14275 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14276 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14277 | |
| 14278 | // The second handler always succeeds. It should only be used where there |
| 14279 | // are multiple auth sessions for server auth in the same network |
| 14280 | // transaction using the same auth scheme. |
| 14281 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14282 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14283 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 14284 | empty_ssl_info, origin, |
| 14285 | NetLogWithSource()); |
| 14286 | second_handler->SetGenerateExpectation(true, OK); |
| 14287 | auth_factory->AddMockHandler(second_handler.release(), |
| 14288 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14289 | } |
| 14290 | if (test_config.proxy_url) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14291 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14292 | ProxyResolutionService::CreateFixed(test_config.proxy_url, |
| 14293 | TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14294 | } else { |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14295 | session_deps_.proxy_resolution_service = |
| 14296 | ProxyResolutionService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14297 | } |
| 14298 | |
| 14299 | HttpRequestInfo request; |
| 14300 | request.method = "GET"; |
| 14301 | request.url = GURL(test_config.server_url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14302 | request.traffic_annotation = |
| 14303 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14304 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14305 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14306 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14307 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 14308 | |
| 14309 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 14310 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14311 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14312 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14313 | const TestRound& read_write_round = test_config.rounds[round]; |
| 14314 | |
| 14315 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14316 | mock_reads.back().push_back(read_write_round.read); |
| 14317 | mock_writes.back().push_back(read_write_round.write); |
| 14318 | |
| 14319 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 14320 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 14321 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14322 | mock_reads.push_back(std::vector<MockRead>()); |
| 14323 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14324 | } |
| 14325 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14326 | if (read_write_round.extra_read) { |
| 14327 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14328 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14329 | if (read_write_round.extra_write) { |
| 14330 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 14331 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14332 | |
| 14333 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14334 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14335 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14336 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14337 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14338 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14339 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14340 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14341 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14342 | mock_reads[i], mock_writes[i])); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14343 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 14344 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14345 | } |
| 14346 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 14347 | // Transaction must be created after DataProviders, so it's destroyed before |
| 14348 | // they are as well. |
| 14349 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 14350 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14351 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14352 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14353 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14354 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14355 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14356 | int rv; |
| 14357 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14358 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14359 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14360 | rv = trans.RestartWithAuth( |
| 14361 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14362 | } |
| 14363 | if (rv == ERR_IO_PENDING) |
| 14364 | rv = callback.WaitForResult(); |
| 14365 | |
| 14366 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14367 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14368 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 14369 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14370 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 14371 | continue; |
| 14372 | } |
| 14373 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14374 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14375 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14376 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14377 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14378 | } |
| 14379 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 14380 | } |
| 14381 | } |
| 14382 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14383 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14384 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14385 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14386 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14387 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14388 | session_deps_.proxy_resolution_service = |
| 14389 | ProxyResolutionService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14390 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14391 | |
| 14392 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14393 | auth_handler->set_connection_based(true); |
| 14394 | std::string auth_challenge = "Mock realm=server"; |
| 14395 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14396 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14397 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14398 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14399 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14400 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14401 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14402 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14403 | int rv = OK; |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 14404 | const HttpResponseInfo* response = nullptr; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14405 | HttpRequestInfo request; |
| 14406 | request.method = "GET"; |
| 14407 | request.url = origin; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14408 | request.traffic_annotation = |
| 14409 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14410 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14411 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14412 | |
| 14413 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 14414 | // to validate that the TCP socket is not released to the pool between |
| 14415 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14416 | HttpNetworkSessionPeer session_peer(session.get()); |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 14417 | CommonConnectJobParams common_connect_job_params( |
| 14418 | session->CreateCommonConnectJobParams()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14419 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
Tarun Bansal | a763509 | 2019-02-20 10:00:59 | [diff] [blame] | 14420 | 50, // Max sockets for pool |
| 14421 | 1, // Max sockets per group |
| 14422 | base::TimeDelta::FromSeconds(10), // unused_idle_socket_timeout |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 14423 | &common_connect_job_params, session_deps_.ssl_config_service.get()); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14424 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 14425 | mock_pool_manager->SetSocketPool(ProxyServer::Direct(), |
| 14426 | base::WrapUnique(transport_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14427 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14428 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14429 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14430 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14431 | |
| 14432 | const MockWrite kGet( |
| 14433 | "GET / HTTP/1.1\r\n" |
| 14434 | "Host: www.example.com\r\n" |
| 14435 | "Connection: keep-alive\r\n\r\n"); |
| 14436 | const MockWrite kGetAuth( |
| 14437 | "GET / HTTP/1.1\r\n" |
| 14438 | "Host: www.example.com\r\n" |
| 14439 | "Connection: keep-alive\r\n" |
| 14440 | "Authorization: auth_token\r\n\r\n"); |
| 14441 | |
| 14442 | const MockRead kServerChallenge( |
| 14443 | "HTTP/1.1 401 Unauthorized\r\n" |
| 14444 | "WWW-Authenticate: Mock realm=server\r\n" |
| 14445 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14446 | "Content-Length: 14\r\n\r\n" |
| 14447 | "Unauthorized\r\n"); |
| 14448 | const MockRead kSuccess( |
| 14449 | "HTTP/1.1 200 OK\r\n" |
| 14450 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14451 | "Content-Length: 3\r\n\r\n" |
| 14452 | "Yes"); |
| 14453 | |
| 14454 | MockWrite writes[] = { |
| 14455 | // First round |
| 14456 | kGet, |
| 14457 | // Second round |
| 14458 | kGetAuth, |
| 14459 | // Third round |
| 14460 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14461 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14462 | kGetAuth, |
| 14463 | // Competing request |
| 14464 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14465 | }; |
| 14466 | MockRead reads[] = { |
| 14467 | // First round |
| 14468 | kServerChallenge, |
| 14469 | // Second round |
| 14470 | kServerChallenge, |
| 14471 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14472 | kServerChallenge, |
| 14473 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14474 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14475 | // Competing response |
| 14476 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14477 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14478 | StaticSocketDataProvider data_provider(reads, writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14479 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14480 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 14481 | const ClientSocketPool::GroupId kSocketGroup( |
| 14482 | HostPortPair("www.example.com", 80), ClientSocketPool::SocketType::kHttp, |
| 14483 | false /* privacy_mode */); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14484 | |
| 14485 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14486 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14487 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14488 | if (rv == ERR_IO_PENDING) |
| 14489 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14490 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14491 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14492 | ASSERT_TRUE(response); |
| 14493 | EXPECT_TRUE(response->auth_challenge); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14494 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14495 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14496 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14497 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14498 | // In between rounds, another request comes in for the same domain. |
| 14499 | // It should not be able to grab the TCP socket that trans has already |
| 14500 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14501 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14502 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14503 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 14504 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14505 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14506 | // callback_compete.WaitForResult at this point would stall forever, |
| 14507 | // since the HttpNetworkTransaction does not release the request back to |
| 14508 | // the pool until after authentication completes. |
| 14509 | |
| 14510 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14511 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14512 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14513 | if (rv == ERR_IO_PENDING) |
| 14514 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14515 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14516 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14517 | ASSERT_TRUE(response); |
| 14518 | EXPECT_FALSE(response->auth_challenge); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14519 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14520 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14521 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14522 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14523 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14524 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14525 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14526 | if (rv == ERR_IO_PENDING) |
| 14527 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14528 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14529 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14530 | ASSERT_TRUE(response); |
| 14531 | EXPECT_FALSE(response->auth_challenge); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14532 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14533 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14534 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14535 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14536 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14537 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14538 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14539 | if (rv == ERR_IO_PENDING) |
| 14540 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14541 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14542 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14543 | ASSERT_TRUE(response); |
| 14544 | EXPECT_FALSE(response->auth_challenge); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14545 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14546 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14547 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 14548 | // auth handler should transition to a DONE state in concert with the remote |
| 14549 | // server. But that's not something we can test here with a mock handler. |
| 14550 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 14551 | auth_handler->state()); |
| 14552 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14553 | // Read the body since the fourth round was successful. This will also |
| 14554 | // release the socket back to the pool. |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 14555 | scoped_refptr<IOBufferWithSize> io_buf = |
| 14556 | base::MakeRefCounted<IOBufferWithSize>(50); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14557 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14558 | if (rv == ERR_IO_PENDING) |
| 14559 | rv = callback.WaitForResult(); |
| 14560 | EXPECT_EQ(3, rv); |
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 | EXPECT_EQ(0, rv); |
| 14563 | // There are still 0 idle sockets, since the trans_compete transaction |
| 14564 | // will be handed it immediately after trans releases it to the group. |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14565 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14566 | |
| 14567 | // The competing request can now finish. Wait for the headers and then |
| 14568 | // read the body. |
| 14569 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14570 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14571 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14572 | if (rv == ERR_IO_PENDING) |
| 14573 | rv = callback.WaitForResult(); |
| 14574 | EXPECT_EQ(3, rv); |
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 | EXPECT_EQ(0, rv); |
| 14577 | |
| 14578 | // Finally, the socket is released to the group. |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14579 | EXPECT_EQ(1u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14580 | } |
| 14581 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14582 | // This tests the case that a request is issued via http instead of spdy after |
| 14583 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14584 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14585 | HttpRequestInfo request; |
| 14586 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14587 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14588 | request.traffic_annotation = |
| 14589 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14590 | |
| 14591 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14592 | MockWrite( |
| 14593 | "GET / HTTP/1.1\r\n" |
| 14594 | "Host: www.example.org\r\n" |
| 14595 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14596 | }; |
| 14597 | |
| 14598 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14599 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 14600 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14601 | MockRead("\r\n"), |
| 14602 | MockRead("hello world"), |
| 14603 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14604 | }; |
| 14605 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14606 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14607 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14608 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14609 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14610 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14611 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14612 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14613 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14614 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14615 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14616 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14617 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14618 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14619 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14620 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14621 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14622 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14623 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14624 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14625 | ASSERT_TRUE(response); |
| 14626 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14627 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14628 | |
| 14629 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14630 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14631 | EXPECT_EQ("hello world", response_data); |
| 14632 | |
| 14633 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14634 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14635 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14636 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 14637 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 14638 | // immediate server closing of the socket. |
| 14639 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14640 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14641 | HttpRequestInfo request; |
| 14642 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14643 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14644 | request.traffic_annotation = |
| 14645 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14646 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14647 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14648 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14649 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14650 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14651 | spdy::SpdySerializedFrame req( |
| 14652 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14653 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14654 | |
| 14655 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14656 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14657 | }; |
| 14658 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14659 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14660 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14661 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14662 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14663 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14664 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14665 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14666 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14667 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14668 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14669 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14670 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14671 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14672 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 14673 | // it gets it. This is needed since the auth handler may get destroyed |
| 14674 | // before we get a chance to query it. |
| 14675 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 14676 | public: |
| 14677 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 14678 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 14679 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14680 | |
| 14681 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14682 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 14683 | const HttpRequestInfo* request, |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 14684 | CompletionOnceCallback callback, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14685 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14686 | *url_ = request->url; |
| 14687 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 14688 | credentials, request, std::move(callback), auth_token); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14689 | } |
| 14690 | |
| 14691 | private: |
| 14692 | GURL* url_; |
| 14693 | }; |
| 14694 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14695 | // Test that if we cancel the transaction as the connection is completing, that |
| 14696 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14697 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14698 | // Setup everything about the connection to complete synchronously, so that |
| 14699 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 14700 | // for is the callback from the HttpStreamRequest. |
| 14701 | // Then cancel the transaction. |
| 14702 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 14703 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14704 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14705 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 14706 | MockRead(SYNCHRONOUS, "hello world"), |
| 14707 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14708 | }; |
| 14709 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14710 | HttpRequestInfo request; |
| 14711 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14712 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14713 | request.traffic_annotation = |
| 14714 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14715 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14716 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14717 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14718 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14719 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14720 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14721 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14722 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14723 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14724 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14725 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14726 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14727 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14728 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14729 | trans.reset(); // Cancel the transaction here. |
| 14730 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14731 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 14732 | } |
| 14733 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14734 | // Test that if a transaction is cancelled after receiving the headers, the |
| 14735 | // stream is drained properly and added back to the socket pool. The main |
| 14736 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 14737 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 14738 | // deleted. |
| 14739 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14740 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14741 | MockRead data_reads[] = { |
| 14742 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 14743 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 14744 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 14745 | MockRead(ASYNC, "1"), |
| 14746 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 14747 | // HttpNetworkTransaction has been deleted. |
| 14748 | MockRead(ASYNC, "2"), |
| 14749 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 14750 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14751 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14752 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14753 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14754 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14755 | |
| 14756 | { |
| 14757 | HttpRequestInfo request; |
| 14758 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14759 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14760 | request.traffic_annotation = |
| 14761 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14762 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14763 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14764 | TestCompletionCallback callback; |
| 14765 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14766 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14767 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14768 | callback.WaitForResult(); |
| 14769 | |
| 14770 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14771 | ASSERT_TRUE(response); |
| 14772 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14773 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14774 | |
| 14775 | // The transaction and HttpRequestInfo are deleted. |
| 14776 | } |
| 14777 | |
| 14778 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14779 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14780 | |
| 14781 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14782 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14783 | } |
| 14784 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14785 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14786 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14787 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14788 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14789 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14790 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14791 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14792 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14793 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14794 | HttpRequestInfo request; |
| 14795 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14796 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14797 | request.traffic_annotation = |
| 14798 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14799 | |
| 14800 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14801 | MockWrite( |
| 14802 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 14803 | "Host: www.example.org\r\n" |
| 14804 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14805 | }; |
| 14806 | |
| 14807 | MockRead data_reads1[] = { |
| 14808 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14809 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14810 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14811 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14812 | }; |
| 14813 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14814 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14815 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14816 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14817 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14818 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14819 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14820 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14821 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14822 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 14823 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14824 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14825 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14826 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14827 | |
| 14828 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14829 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14830 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14831 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14832 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14833 | |
| 14834 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14835 | EXPECT_EQ(200, response->headers->response_code()); |
| 14836 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14837 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14838 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14839 | HostPortPair::FromString("myproxy:70")), |
| 14840 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14841 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14842 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14843 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14844 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14845 | |
| 14846 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14847 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14848 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14849 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14850 | } |
| 14851 | |
| 14852 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14853 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14854 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14855 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14856 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14857 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14858 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14859 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14860 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14861 | HttpRequestInfo request; |
| 14862 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14863 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14864 | request.traffic_annotation = |
| 14865 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14866 | |
| 14867 | // Since we have proxy, should try to establish tunnel. |
| 14868 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14869 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14870 | "Host: www.example.org:443\r\n" |
| 14871 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14872 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14873 | MockWrite("GET / HTTP/1.1\r\n" |
| 14874 | "Host: www.example.org\r\n" |
| 14875 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14876 | }; |
| 14877 | |
| 14878 | MockRead data_reads1[] = { |
| 14879 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14880 | |
| 14881 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14882 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14883 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14884 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14885 | }; |
| 14886 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14887 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14888 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14889 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14890 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14891 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14892 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14893 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14894 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14895 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14896 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14897 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 14898 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14899 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14900 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14901 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14902 | |
| 14903 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14904 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14905 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14906 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14907 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14908 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14909 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14910 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14911 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14912 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14913 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14914 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14915 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14916 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14917 | |
| 14918 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14919 | EXPECT_EQ(200, response->headers->response_code()); |
| 14920 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14921 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14922 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14923 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14924 | HostPortPair::FromString("myproxy:70")), |
| 14925 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14926 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14927 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14928 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14929 | |
| 14930 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14931 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14932 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14933 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14934 | } |
| 14935 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14936 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 14937 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14938 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14939 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14940 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14941 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14942 | BoundTestNetLog log; |
| 14943 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14944 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14945 | |
| 14946 | HttpRequestInfo request; |
| 14947 | request.method = "GET"; |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14948 | request.url = GURL("https://[::2]:443/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14949 | request.traffic_annotation = |
| 14950 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14951 | |
| 14952 | // Since we have proxy, should try to establish tunnel. |
| 14953 | MockWrite data_writes1[] = { |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14954 | MockWrite("CONNECT [::2]:443 HTTP/1.1\r\n" |
| 14955 | "Host: [::2]:443\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14956 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 14957 | |
| 14958 | MockWrite("GET / HTTP/1.1\r\n" |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14959 | "Host: [::2]\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14960 | "Connection: keep-alive\r\n\r\n"), |
| 14961 | }; |
| 14962 | |
| 14963 | MockRead data_reads1[] = { |
| 14964 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14965 | |
| 14966 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14967 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14968 | MockRead("Content-Length: 100\r\n\r\n"), |
| 14969 | MockRead(SYNCHRONOUS, OK), |
| 14970 | }; |
| 14971 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14972 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14973 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14974 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14975 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14976 | |
| 14977 | TestCompletionCallback callback1; |
| 14978 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14979 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14980 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14981 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14982 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14983 | |
| 14984 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14985 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14986 | TestNetLogEntry::List entries; |
| 14987 | log.GetEntries(&entries); |
| 14988 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14989 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14990 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14991 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14992 | entries, pos, |
| 14993 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14994 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14995 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14996 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14997 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14998 | |
| 14999 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 15000 | EXPECT_EQ(200, response->headers->response_code()); |
| 15001 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 15002 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 15003 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 15004 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 15005 | HostPortPair::FromString("myproxy:70")), |
| 15006 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15007 | |
| 15008 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15009 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15010 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 15011 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 15012 | } |
| 15013 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15014 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 15015 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15016 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15017 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 15018 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15019 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15020 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15021 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15022 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15023 | HttpRequestInfo request; |
| 15024 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15025 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15026 | request.traffic_annotation = |
| 15027 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15028 | |
| 15029 | // Since we have proxy, should try to establish tunnel. |
| 15030 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15031 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15032 | "Host: www.example.org:443\r\n" |
| 15033 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15034 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15035 | MockWrite("GET / HTTP/1.1\r\n" |
| 15036 | "Host: www.example.org\r\n" |
| 15037 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15038 | }; |
| 15039 | |
| 15040 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15041 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15042 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15043 | }; |
| 15044 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15045 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15046 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15047 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15048 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15049 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15050 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15051 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15052 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 15053 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15054 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15055 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15056 | |
| 15057 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15058 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 15059 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 15060 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15061 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15062 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 15063 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15064 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 15065 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15066 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 15067 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15068 | } |
| 15069 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15070 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15071 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15072 | spdy::SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15073 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15074 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15075 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15076 | spdy::SpdySerializedFrame resp( |
| 15077 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15078 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15079 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15080 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15081 | }; |
| 15082 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15083 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15084 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15085 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15086 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15087 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15088 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15089 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15090 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15091 | |
| 15092 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15093 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 15094 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 15095 | PRIVACY_MODE_DISABLED, |
| 15096 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 15097 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 15098 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15099 | |
| 15100 | HttpRequestInfo request; |
| 15101 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15102 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15103 | request.traffic_annotation = |
| 15104 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15105 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15106 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15107 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15108 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15109 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15110 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15111 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15112 | } |
| 15113 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15114 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15115 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 15116 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15117 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15118 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15119 | request_info.url = GURL("https://www.example.com/"); |
| 15120 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15121 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15122 | request_info.traffic_annotation = |
| 15123 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15124 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15125 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15126 | MockWrite data_writes[] = { |
| 15127 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15128 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15129 | StaticSocketDataProvider data(base::span<MockRead>(), data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15130 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15131 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15132 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15133 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15134 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15135 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15136 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15137 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15138 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15139 | rv = callback.WaitForResult(); |
| 15140 | ASSERT_EQ(error, rv); |
| 15141 | } |
| 15142 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15143 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15144 | // Just check a grab bag of cert errors. |
| 15145 | static const int kErrors[] = { |
| 15146 | ERR_CERT_COMMON_NAME_INVALID, |
| 15147 | ERR_CERT_AUTHORITY_INVALID, |
| 15148 | ERR_CERT_DATE_INVALID, |
| 15149 | }; |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 15150 | for (size_t i = 0; i < base::size(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15151 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 15152 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15153 | } |
| 15154 | } |
| 15155 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15156 | // Ensure that a client certificate is removed from the SSL client auth |
| 15157 | // cache when: |
| 15158 | // 1) No proxy is involved. |
| 15159 | // 2) TLS False Start is disabled. |
| 15160 | // 3) The initial TLS handshake requests a client certificate. |
| 15161 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15162 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15163 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15164 | request_info.url = GURL("https://www.example.com/"); |
| 15165 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15166 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15167 | request_info.traffic_annotation = |
| 15168 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15169 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15170 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15171 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15172 | |
| 15173 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 15174 | // CertificateRequest is received for the first time, the handshake will |
| 15175 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15176 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15177 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15178 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15179 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15180 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15181 | |
| 15182 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 15183 | // False Start is not being used, the result of the SSL handshake will be |
| 15184 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 15185 | // matches the result of a server sending a handshake_failure alert, |
| 15186 | // rather than a Finished message, because it requires a client |
| 15187 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15188 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15189 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15190 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15191 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15192 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15193 | |
| 15194 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 15195 | // connection to a server fails during an SSL handshake, |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15196 | // HttpNetworkTransaction will attempt to fallback to TLSv1.2 if the previous |
| 15197 | // connection was attempted with TLSv1.3. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15198 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15199 | // requiring a client certificate, this fallback handshake should also |
| 15200 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15201 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15202 | ssl_data3.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15203 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15204 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15205 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15206 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15207 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15208 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 15209 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 15210 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 15211 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15212 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15213 | // requiring a client certificate, this fallback handshake should also |
| 15214 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15215 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15216 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15217 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15218 | StaticSocketDataProvider data4; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15219 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15220 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15221 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15222 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15223 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15224 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15225 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15226 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15227 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15228 | |
| 15229 | // Complete the SSL handshake, which should abort due to requiring a |
| 15230 | // client certificate. |
| 15231 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15232 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15233 | |
| 15234 | // Indicate that no certificate should be supplied. From the perspective |
| 15235 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15236 | // certificate, so this is the same as supply a |
| 15237 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15238 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15239 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15240 | |
| 15241 | // Ensure the certificate was added to the client auth cache before |
| 15242 | // allowing the connection to continue restarting. |
| 15243 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15244 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15245 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15246 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15247 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15248 | |
| 15249 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15250 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15251 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15252 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15253 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15254 | |
| 15255 | // Ensure that the client certificate is removed from the cache on a |
| 15256 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15257 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15258 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15259 | } |
| 15260 | |
| 15261 | // Ensure that a client certificate is removed from the SSL client auth |
| 15262 | // cache when: |
| 15263 | // 1) No proxy is involved. |
| 15264 | // 2) TLS False Start is enabled. |
| 15265 | // 3) The initial TLS handshake requests a client certificate. |
| 15266 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15267 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15268 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15269 | request_info.url = GURL("https://www.example.com/"); |
| 15270 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15271 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15272 | request_info.traffic_annotation = |
| 15273 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15274 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15275 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15276 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15277 | |
| 15278 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 15279 | // return successfully after reading up to the peer's Certificate message. |
| 15280 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 15281 | // enqueue application data to be sent in the same packet as the |
| 15282 | // ChangeCipherSpec and Finished messages. |
| 15283 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 15284 | // called, which expects to process the peer's ChangeCipherSpec and |
| 15285 | // Finished messages. If there was an error negotiating with the peer, |
| 15286 | // such as due to the peer requiring a client certificate when none was |
| 15287 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 15288 | // called. |
| 15289 | |
| 15290 | // Like the non-False Start case, when a client certificate is requested by |
| 15291 | // the peer, the handshake is aborted during the Connect() call. |
| 15292 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15293 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15294 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15295 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15296 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15297 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15298 | |
| 15299 | // When a client certificate is supplied, Connect() will not be aborted |
| 15300 | // when the peer requests the certificate. Instead, the handshake will |
| 15301 | // artificially succeed, allowing the caller to write the HTTP request to |
| 15302 | // the socket. The handshake messages are not processed until Read() is |
| 15303 | // called, which then detects that the handshake was aborted, due to the |
| 15304 | // peer sending a handshake_failure because it requires a client |
| 15305 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15306 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15307 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15308 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15309 | MockRead data2_reads[] = { |
| 15310 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15311 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15312 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15313 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15314 | |
| 15315 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15316 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 15317 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15318 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15319 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15320 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15321 | StaticSocketDataProvider data3(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15322 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15323 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15324 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 15325 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15326 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15327 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15328 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15329 | StaticSocketDataProvider data4(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15330 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15331 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15332 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15333 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15334 | ssl_data5.cert_request_info = cert_request.get(); |
| 15335 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15336 | StaticSocketDataProvider data5(data2_reads, base::span<MockWrite>()); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15337 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 15338 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15339 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15340 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15341 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15342 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15343 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15344 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15345 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15346 | |
| 15347 | // Complete the SSL handshake, which should abort due to requiring a |
| 15348 | // client certificate. |
| 15349 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15350 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15351 | |
| 15352 | // Indicate that no certificate should be supplied. From the perspective |
| 15353 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15354 | // certificate, so this is the same as supply a |
| 15355 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15356 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15357 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15358 | |
| 15359 | // Ensure the certificate was added to the client auth cache before |
| 15360 | // allowing the connection to continue restarting. |
| 15361 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15362 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15363 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15364 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15365 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15366 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15367 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15368 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15369 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15370 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15371 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15372 | |
| 15373 | // Ensure that the client certificate is removed from the cache on a |
| 15374 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15375 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15376 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15377 | } |
| 15378 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15379 | // Ensure that a client certificate is removed from the SSL client auth |
| 15380 | // cache when: |
| 15381 | // 1) An HTTPS proxy is involved. |
| 15382 | // 3) The HTTPS proxy requests a client certificate. |
| 15383 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 15384 | // proxy. |
| 15385 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 15386 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15387 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15388 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 15389 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15390 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15391 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15392 | |
| 15393 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15394 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15395 | |
| 15396 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 15397 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 15398 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 15399 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15400 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15401 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15402 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15403 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15404 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15405 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15406 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15407 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15408 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15409 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15410 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15411 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15412 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 15413 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15414 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15415 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15416 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15417 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15418 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15419 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15420 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15421 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15422 | requests[0].url = GURL("https://www.example.com/"); |
| 15423 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15424 | requests[0].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15425 | requests[0].traffic_annotation = |
| 15426 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15427 | |
| 15428 | requests[1].url = GURL("http://www.example.com/"); |
| 15429 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15430 | requests[1].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15431 | requests[1].traffic_annotation = |
| 15432 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15433 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 15434 | for (size_t i = 0; i < base::size(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15435 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15436 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15437 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15438 | |
| 15439 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15440 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15441 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15442 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15443 | |
| 15444 | // Complete the SSL handshake, which should abort due to requiring a |
| 15445 | // client certificate. |
| 15446 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15447 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15448 | |
| 15449 | // Indicate that no certificate should be supplied. From the perspective |
| 15450 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15451 | // certificate, so this is the same as supply a |
| 15452 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15453 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15454 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15455 | |
| 15456 | // Ensure the certificate was added to the client auth cache before |
| 15457 | // allowing the connection to continue restarting. |
| 15458 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15459 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15460 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15461 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15462 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15463 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 15464 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15465 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15466 | HostPortPair("www.example.com", 443), &client_cert, |
| 15467 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15468 | |
| 15469 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 15470 | // then consume ssl_data3, which should also fail. The result code is |
| 15471 | // checked against what ssl_data3 should return. |
| 15472 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15473 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15474 | |
| 15475 | // Now that the new handshake has failed, ensure that the client |
| 15476 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15477 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15478 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15479 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15480 | HostPortPair("www.example.com", 443), &client_cert, |
| 15481 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15482 | } |
| 15483 | } |
| 15484 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15485 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15486 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15487 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15488 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15489 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15490 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15491 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15492 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15493 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15494 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15495 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15496 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15497 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15498 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15499 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15500 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15501 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15502 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15503 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15504 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15505 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15506 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15507 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15508 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15509 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15510 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15511 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15512 | }; |
| 15513 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15514 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15515 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15516 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15517 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15518 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15519 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15520 | HttpRequestInfo request1; |
| 15521 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15522 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15523 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15524 | request1.traffic_annotation = |
| 15525 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15526 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15527 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15528 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15529 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15530 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15531 | |
| 15532 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15533 | ASSERT_TRUE(response); |
| 15534 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15535 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15536 | |
| 15537 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15538 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15539 | EXPECT_EQ("hello!", response_data); |
| 15540 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15541 | // Preload mail.example.com into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15542 | rv = session_deps_.host_resolver->LoadIntoCache( |
| 15543 | HostPortPair("mail.example.com", 443), base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15544 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15545 | |
| 15546 | HttpRequestInfo request2; |
| 15547 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15548 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15549 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15550 | request2.traffic_annotation = |
| 15551 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15552 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15553 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15554 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15555 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15556 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15557 | |
| 15558 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15559 | ASSERT_TRUE(response); |
| 15560 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15561 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15562 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15563 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15564 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15565 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15566 | } |
| 15567 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15568 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15569 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15570 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15571 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15572 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15573 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15574 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15575 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15576 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15577 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15578 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15579 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15580 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15581 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15582 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15583 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15584 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15585 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15586 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15587 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15588 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15589 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15590 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15591 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15592 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15593 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15594 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15595 | }; |
| 15596 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15597 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15598 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15599 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15600 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15601 | |
| 15602 | TestCompletionCallback callback; |
| 15603 | HttpRequestInfo request1; |
| 15604 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15605 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15606 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15607 | request1.traffic_annotation = |
| 15608 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15609 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15610 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15611 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15612 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15613 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15614 | |
| 15615 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15616 | ASSERT_TRUE(response); |
| 15617 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15618 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15619 | |
| 15620 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15621 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15622 | EXPECT_EQ("hello!", response_data); |
| 15623 | |
| 15624 | HttpRequestInfo request2; |
| 15625 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15626 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15627 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15628 | request2.traffic_annotation = |
| 15629 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15630 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15631 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15632 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15633 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15634 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15635 | |
| 15636 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15637 | ASSERT_TRUE(response); |
| 15638 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15639 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15640 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15641 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15642 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15643 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15644 | } |
| 15645 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15646 | // Regression test for https://crbug.com/546991. |
| 15647 | // The server might not be able to serve an IP pooled request, and might send a |
| 15648 | // 421 Misdirected Request response status to indicate this. |
| 15649 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 15650 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 15651 | // Two hosts resolve to the same IP address. |
| 15652 | const std::string ip_addr = "1.2.3.4"; |
| 15653 | IPAddress ip; |
| 15654 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 15655 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15656 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15657 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15658 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 15659 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 15660 | |
| 15661 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15662 | |
| 15663 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15664 | spdy::SpdySerializedFrame req1( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15665 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 15666 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15667 | spdy::SpdySerializedFrame req2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15668 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15669 | spdy::SpdySerializedFrame rst( |
| 15670 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15671 | MockWrite writes1[] = { |
| 15672 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 15673 | CreateMockWrite(rst, 6), |
| 15674 | }; |
| 15675 | |
| 15676 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15677 | spdy::SpdySerializedFrame resp1( |
| 15678 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15679 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15680 | spdy::SpdyHeaderBlock response_headers; |
| 15681 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 15682 | spdy::SpdySerializedFrame resp2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15683 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 15684 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 15685 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 15686 | |
| 15687 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15688 | SequencedSocketData data1(connect1, reads1, writes1); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15689 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15690 | |
| 15691 | AddSSLSocketData(); |
| 15692 | |
| 15693 | // Retry the second request on a second connection. |
| 15694 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15695 | spdy::SpdySerializedFrame req3( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15696 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 15697 | MockWrite writes2[] = { |
| 15698 | CreateMockWrite(req3, 0), |
| 15699 | }; |
| 15700 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15701 | spdy::SpdySerializedFrame resp3( |
| 15702 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15703 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15704 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 15705 | MockRead(ASYNC, 0, 3)}; |
| 15706 | |
| 15707 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15708 | SequencedSocketData data2(connect2, reads2, writes2); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15709 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15710 | |
| 15711 | AddSSLSocketData(); |
| 15712 | |
| 15713 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15714 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 15715 | HostPortPair("mail.example.com", 443), base::nullopt); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15716 | EXPECT_THAT(rv, IsOk()); |
| 15717 | |
| 15718 | HttpRequestInfo request1; |
| 15719 | request1.method = "GET"; |
| 15720 | request1.url = GURL("https://www.example.org/"); |
| 15721 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15722 | request1.traffic_annotation = |
| 15723 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15724 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15725 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15726 | TestCompletionCallback callback; |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15727 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 15728 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15729 | rv = callback.WaitForResult(); |
| 15730 | EXPECT_THAT(rv, IsOk()); |
| 15731 | |
| 15732 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 15733 | ASSERT_TRUE(response); |
| 15734 | ASSERT_TRUE(response->headers); |
| 15735 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15736 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15737 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15738 | std::string response_data; |
| 15739 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 15740 | EXPECT_EQ("hello!", response_data); |
| 15741 | |
| 15742 | HttpRequestInfo request2; |
| 15743 | request2.method = "GET"; |
| 15744 | request2.url = GURL("https://mail.example.org/"); |
| 15745 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15746 | request2.traffic_annotation = |
| 15747 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15748 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15749 | |
| 15750 | BoundTestNetLog log; |
| 15751 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 15752 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15753 | rv = callback.WaitForResult(); |
| 15754 | EXPECT_THAT(rv, IsOk()); |
| 15755 | |
| 15756 | response = trans2.GetResponseInfo(); |
| 15757 | ASSERT_TRUE(response); |
| 15758 | ASSERT_TRUE(response->headers); |
| 15759 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15760 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15761 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15762 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 15763 | EXPECT_EQ("hello!", response_data); |
| 15764 | |
| 15765 | TestNetLogEntry::List entries; |
| 15766 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15767 | ExpectLogContainsSomewhere( |
| 15768 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15769 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15770 | } |
| 15771 | |
| 15772 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 15773 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 15774 | // portions of the response. |
| 15775 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 15776 | // Two hosts resolve to the same IP address. |
| 15777 | const std::string ip_addr = "1.2.3.4"; |
| 15778 | IPAddress ip; |
| 15779 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 15780 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15781 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15782 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15783 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 15784 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 15785 | |
| 15786 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15787 | |
| 15788 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15789 | spdy::SpdySerializedFrame req1( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15790 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 15791 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15792 | spdy::SpdySerializedFrame req2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15793 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15794 | spdy::SpdySerializedFrame rst( |
| 15795 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15796 | MockWrite writes1[] = { |
| 15797 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 15798 | CreateMockWrite(rst, 6), |
| 15799 | }; |
| 15800 | |
| 15801 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15802 | spdy::SpdySerializedFrame resp1( |
| 15803 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15804 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15805 | spdy::SpdyHeaderBlock response_headers; |
| 15806 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 15807 | spdy::SpdySerializedFrame resp2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15808 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 15809 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 15810 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 15811 | |
| 15812 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15813 | SequencedSocketData data1(connect1, reads1, writes1); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15814 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15815 | |
| 15816 | AddSSLSocketData(); |
| 15817 | |
| 15818 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 15819 | // Retry again. |
| 15820 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15821 | spdy::SpdySerializedFrame req3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15822 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 15823 | MockWrite writes2[] = { |
| 15824 | CreateMockWrite(req3, 0), |
| 15825 | }; |
| 15826 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15827 | spdy::SpdySerializedFrame resp3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15828 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15829 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15830 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 15831 | MockRead(ASYNC, 0, 3)}; |
| 15832 | |
| 15833 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15834 | SequencedSocketData data2(connect2, reads2, writes2); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15835 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15836 | |
| 15837 | AddSSLSocketData(); |
| 15838 | |
| 15839 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15840 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 15841 | HostPortPair("mail.example.com", 443), base::nullopt); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15842 | EXPECT_THAT(rv, IsOk()); |
| 15843 | |
| 15844 | HttpRequestInfo request1; |
| 15845 | request1.method = "GET"; |
| 15846 | request1.url = GURL("https://www.example.org/"); |
| 15847 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15848 | request1.traffic_annotation = |
| 15849 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15850 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15851 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15852 | TestCompletionCallback callback; |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15853 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 15854 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15855 | rv = callback.WaitForResult(); |
| 15856 | EXPECT_THAT(rv, IsOk()); |
| 15857 | |
| 15858 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 15859 | ASSERT_TRUE(response); |
| 15860 | ASSERT_TRUE(response->headers); |
| 15861 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15862 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15863 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15864 | std::string response_data; |
| 15865 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 15866 | EXPECT_EQ("hello!", response_data); |
| 15867 | |
| 15868 | HttpRequestInfo request2; |
| 15869 | request2.method = "GET"; |
| 15870 | request2.url = GURL("https://mail.example.org/"); |
| 15871 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15872 | request2.traffic_annotation = |
| 15873 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15874 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15875 | |
| 15876 | BoundTestNetLog log; |
| 15877 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 15878 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15879 | rv = callback.WaitForResult(); |
| 15880 | EXPECT_THAT(rv, IsOk()); |
| 15881 | |
| 15882 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 15883 | // caller. |
| 15884 | response = trans2.GetResponseInfo(); |
| 15885 | ASSERT_TRUE(response); |
| 15886 | ASSERT_TRUE(response->headers); |
| 15887 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 15888 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15889 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15890 | EXPECT_TRUE(response->ssl_info.cert); |
| 15891 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 15892 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15893 | } |
| 15894 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15895 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 15896 | UseIPConnectionPoolingWithHostCacheExpiration) { |
Eric Orth | 1da75de | 2019-02-20 21:10:34 | [diff] [blame] | 15897 | // Set up HostResolver to invalidate cached entries after 1 cached resolve. |
| 15898 | session_deps_.host_resolver = |
| 15899 | std::make_unique<MockCachingHostResolver>(1 /* cache_invalidation_num */); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15900 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15901 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15902 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15903 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15904 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15905 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15906 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15907 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15908 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15909 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15910 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15911 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15912 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15913 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15914 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15915 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15916 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15917 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15918 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15919 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15920 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15921 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15922 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15923 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15924 | }; |
| 15925 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15926 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15927 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15928 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15929 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15930 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15931 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15932 | HttpRequestInfo request1; |
| 15933 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15934 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15935 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15936 | request1.traffic_annotation = |
| 15937 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15938 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15939 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15940 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15941 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15942 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15943 | |
| 15944 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15945 | ASSERT_TRUE(response); |
| 15946 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15947 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15948 | |
| 15949 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15950 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15951 | EXPECT_EQ("hello!", response_data); |
| 15952 | |
| 15953 | // Preload cache entries into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15954 | rv = session_deps_.host_resolver->LoadIntoCache( |
| 15955 | HostPortPair("mail.example.com", 443), base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15956 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15957 | |
| 15958 | HttpRequestInfo request2; |
| 15959 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15960 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15961 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15962 | request2.traffic_annotation = |
| 15963 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15964 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15965 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15966 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15967 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15968 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15969 | |
| 15970 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15971 | ASSERT_TRUE(response); |
| 15972 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15973 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15974 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15975 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15976 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15977 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15978 | } |
| 15979 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15980 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15981 | const std::string https_url = "https://www.example.org:8080/"; |
| 15982 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15983 | |
| 15984 | // SPDY GET for HTTPS URL |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15985 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15986 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15987 | |
| 15988 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15989 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15990 | }; |
| 15991 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15992 | spdy::SpdySerializedFrame resp1( |
| 15993 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15994 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15995 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15996 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15997 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15998 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15999 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 16000 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16001 | |
| 16002 | // HTTP GET for the HTTP URL |
| 16003 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 16004 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 16005 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16006 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 16007 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16008 | }; |
| 16009 | |
| 16010 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 16011 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 16012 | MockRead(ASYNC, 2, "hello"), |
| 16013 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16014 | }; |
| 16015 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16016 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16017 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16018 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16019 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16020 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16021 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 16022 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16023 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16024 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16025 | |
| 16026 | // Start the first transaction to set up the SpdySession |
| 16027 | HttpRequestInfo request1; |
| 16028 | request1.method = "GET"; |
| 16029 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16030 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16031 | request1.traffic_annotation = |
| 16032 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16033 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16034 | TestCompletionCallback callback1; |
| 16035 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16036 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16037 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16038 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16039 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16040 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16041 | |
| 16042 | // Now, start the HTTP request |
| 16043 | HttpRequestInfo request2; |
| 16044 | request2.method = "GET"; |
| 16045 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16046 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16047 | request2.traffic_annotation = |
| 16048 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16049 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16050 | TestCompletionCallback callback2; |
| 16051 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16052 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16053 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16054 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16055 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16056 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16057 | } |
| 16058 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16059 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 16060 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16061 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16062 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 16063 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16064 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16065 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16066 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16067 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16068 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16069 | |
| 16070 | // No data should be read from the alternative, because HTTP/1.1 is |
| 16071 | // negotiated. |
| 16072 | StaticSocketDataProvider data; |
| 16073 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16074 | |
| 16075 | // 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] | 16076 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16077 | // mocked. This way the request relies on the alternate Job. |
| 16078 | StaticSocketDataProvider data_refused; |
| 16079 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 16080 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 16081 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16082 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16083 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16084 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16085 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16086 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16087 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16088 | http_server_properties->SetHttp2AlternativeService( |
| 16089 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16090 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16091 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16092 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16093 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16094 | request.url = GURL("https://www.example.org:443"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16095 | request.traffic_annotation = |
| 16096 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16097 | TestCompletionCallback callback; |
| 16098 | |
| 16099 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16100 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16101 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16102 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16103 | } |
| 16104 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16105 | // 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] | 16106 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16107 | // succeeds, the request should succeed, even if the latter fails because |
| 16108 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16109 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16110 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 16111 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16112 | |
| 16113 | // Negotiate HTTP/1.1 with alternative. |
| 16114 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16115 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16116 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 16117 | |
| 16118 | // No data should be read from the alternative, because HTTP/1.1 is |
| 16119 | // negotiated. |
| 16120 | StaticSocketDataProvider data; |
| 16121 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16122 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16123 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16124 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16125 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16126 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 16127 | |
| 16128 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16129 | MockWrite("GET / HTTP/1.1\r\n" |
| 16130 | "Host: www.example.org\r\n" |
| 16131 | "Connection: keep-alive\r\n\r\n"), |
| 16132 | MockWrite("GET /second HTTP/1.1\r\n" |
| 16133 | "Host: www.example.org\r\n" |
| 16134 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16135 | }; |
| 16136 | |
| 16137 | MockRead http_reads[] = { |
| 16138 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16139 | MockRead("Content-Type: text/html\r\n"), |
| 16140 | MockRead("Content-Length: 6\r\n\r\n"), |
| 16141 | MockRead("foobar"), |
| 16142 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16143 | MockRead("Content-Type: text/html\r\n"), |
| 16144 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16145 | MockRead("another"), |
| 16146 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16147 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16148 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16149 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16150 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16151 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16152 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16153 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16154 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16155 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16156 | http_server_properties->SetHttp2AlternativeService( |
| 16157 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16158 | |
| 16159 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 16160 | HttpRequestInfo request1; |
| 16161 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16162 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16163 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16164 | request1.traffic_annotation = |
| 16165 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16166 | TestCompletionCallback callback1; |
| 16167 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16168 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16169 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16170 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16171 | |
| 16172 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16173 | ASSERT_TRUE(response1); |
| 16174 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16175 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 16176 | |
| 16177 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16178 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16179 | EXPECT_EQ("foobar", response_data1); |
| 16180 | |
| 16181 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 16182 | // for alternative service. |
| 16183 | EXPECT_TRUE( |
| 16184 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 16185 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16186 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16187 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16188 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16189 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 16190 | HttpRequestInfo request2; |
| 16191 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16192 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16193 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16194 | request2.traffic_annotation = |
| 16195 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16196 | TestCompletionCallback callback2; |
| 16197 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16198 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16199 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16200 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16201 | |
| 16202 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16203 | ASSERT_TRUE(response2); |
| 16204 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16205 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 16206 | |
| 16207 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16208 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16209 | EXPECT_EQ("another", response_data2); |
| 16210 | } |
| 16211 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16212 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 16213 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 16214 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16215 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16216 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16217 | HostPortPair alternative("alternative.example.org", 443); |
| 16218 | std::string origin_url = "https://origin.example.org:443"; |
| 16219 | std::string alternative_url = "https://alternative.example.org:443"; |
| 16220 | |
| 16221 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 16222 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16223 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16224 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16225 | |
| 16226 | // HTTP/1.1 data for |request1| and |request2|. |
| 16227 | MockWrite http_writes[] = { |
| 16228 | MockWrite( |
| 16229 | "GET / HTTP/1.1\r\n" |
| 16230 | "Host: alternative.example.org\r\n" |
| 16231 | "Connection: keep-alive\r\n\r\n"), |
| 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 | }; |
| 16237 | |
| 16238 | MockRead http_reads[] = { |
| 16239 | MockRead( |
| 16240 | "HTTP/1.1 200 OK\r\n" |
| 16241 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16242 | "Content-Length: 40\r\n\r\n" |
| 16243 | "first HTTP/1.1 response from alternative"), |
| 16244 | MockRead( |
| 16245 | "HTTP/1.1 200 OK\r\n" |
| 16246 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16247 | "Content-Length: 41\r\n\r\n" |
| 16248 | "second HTTP/1.1 response from alternative"), |
| 16249 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16250 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16251 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16252 | |
| 16253 | // This test documents that an alternate Job should not pool to an already |
| 16254 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16255 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16256 | StaticSocketDataProvider data_refused; |
| 16257 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 16258 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 16259 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16260 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16261 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16262 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16263 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16264 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16265 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16266 | http_server_properties->SetHttp2AlternativeService( |
| 16267 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16268 | |
| 16269 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16270 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16271 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16272 | request1.method = "GET"; |
| 16273 | request1.url = GURL(alternative_url); |
| 16274 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16275 | request1.traffic_annotation = |
| 16276 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16277 | TestCompletionCallback callback1; |
| 16278 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16279 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16280 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16281 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16282 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16283 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16284 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16285 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16286 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 16287 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16288 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16289 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 16290 | |
| 16291 | // Request for origin.example.org, which has an alternative service. This |
| 16292 | // will start two Jobs: the alternative looks for connections to pool to, |
| 16293 | // 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] | 16294 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16295 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16296 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16297 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16298 | request2.method = "GET"; |
| 16299 | request2.url = GURL(origin_url); |
| 16300 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16301 | request2.traffic_annotation = |
| 16302 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16303 | TestCompletionCallback callback2; |
| 16304 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16305 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16306 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16307 | |
| 16308 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 16309 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16310 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16311 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16312 | request3.method = "GET"; |
| 16313 | request3.url = GURL(alternative_url); |
| 16314 | request3.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16315 | request3.traffic_annotation = |
| 16316 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16317 | TestCompletionCallback callback3; |
| 16318 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16319 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16320 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16321 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16322 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16323 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16324 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16325 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16326 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 16327 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16328 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16329 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 16330 | } |
| 16331 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16332 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16333 | const std::string https_url = "https://www.example.org:8080/"; |
| 16334 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16335 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16336 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16337 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16338 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16339 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16340 | const HostPortPair host_port_pair("www.example.org", 8080); |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 16341 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
| 16342 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 16343 | host_port_pair)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16344 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16345 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16346 | spdy::SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 16347 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 16348 | |
| 16349 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16350 | spdy::SpdyHeaderBlock req2_block; |
| 16351 | req2_block[spdy::kHttp2MethodHeader] = "GET"; |
| 16352 | req2_block[spdy::kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 16353 | req2_block[spdy::kHttp2SchemeHeader] = "http"; |
| 16354 | req2_block[spdy::kHttp2PathHeader] = "/"; |
| 16355 | spdy::SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16356 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16357 | |
| 16358 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16359 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 16360 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16361 | }; |
| 16362 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16363 | spdy::SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16364 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16365 | spdy::SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16366 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16367 | spdy::SpdySerializedFrame body1( |
| 16368 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 16369 | spdy::SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16370 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16371 | spdy::SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16372 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16373 | spdy::SpdySerializedFrame resp2( |
| 16374 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16375 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16376 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16377 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16378 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16379 | CreateMockRead(wrapped_resp1, 4), |
| 16380 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16381 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16382 | CreateMockRead(resp2, 8), |
| 16383 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16384 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 16385 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16386 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16387 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16388 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 16389 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16390 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 16391 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16392 | ProxyResolutionService::CreateFixedFromPacResult( |
| 16393 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 16394 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16395 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16396 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16397 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16398 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16399 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16400 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16401 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16402 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16403 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16404 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16405 | |
| 16406 | // Start the first transaction to set up the SpdySession |
| 16407 | HttpRequestInfo request1; |
| 16408 | request1.method = "GET"; |
| 16409 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16410 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16411 | request1.traffic_annotation = |
| 16412 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16413 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16414 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16415 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16416 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16417 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16418 | data1.RunUntilPaused(); |
| 16419 | base::RunLoop().RunUntilIdle(); |
| 16420 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16421 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16422 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16423 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16424 | LoadTimingInfo load_timing_info1; |
| 16425 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 16426 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 16427 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 16428 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16429 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16430 | HttpRequestInfo request2; |
| 16431 | request2.method = "GET"; |
| 16432 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16433 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16434 | request2.traffic_annotation = |
| 16435 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16436 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16437 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16438 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16439 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16440 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16441 | data1.RunUntilPaused(); |
| 16442 | base::RunLoop().RunUntilIdle(); |
| 16443 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16444 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16445 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16446 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16447 | |
| 16448 | LoadTimingInfo load_timing_info2; |
| 16449 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 16450 | // The established SPDY sessions is considered reused by the HTTP request. |
| 16451 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 16452 | // HTTP requests over a SPDY session should have a different connection |
| 16453 | // socket_log_id than requests over a tunnel. |
| 16454 | 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] | 16455 | } |
| 16456 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16457 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 16458 | // that we do not pool other origins that resolve to the same IP when |
| 16459 | // the certificate does not match the new origin. |
| 16460 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16461 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16462 | const std::string url1 = "http://www.example.org/"; |
| 16463 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16464 | const std::string ip_addr = "1.2.3.4"; |
| 16465 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16466 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16467 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16468 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16469 | // SPDY GET for HTTP URL (through SPDY proxy) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16470 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16471 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16472 | spdy::SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16473 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16474 | |
| 16475 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16476 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16477 | }; |
| 16478 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16479 | spdy::SpdySerializedFrame resp1( |
| 16480 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16481 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16482 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16483 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 16484 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16485 | }; |
| 16486 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16487 | SequencedSocketData data1(reads1, writes1); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 16488 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 16489 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16490 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 16491 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16492 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16493 | |
| 16494 | // SPDY GET for HTTPS URL (direct) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16495 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16496 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16497 | |
| 16498 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16499 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16500 | }; |
| 16501 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16502 | spdy::SpdySerializedFrame resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16503 | spdy_util_secure.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16504 | spdy::SpdySerializedFrame body2( |
| 16505 | spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16506 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16507 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16508 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16509 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16510 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16511 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16512 | |
| 16513 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 16514 | // all others direct. |
| 16515 | ProxyConfig proxy_config; |
| 16516 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16517 | session_deps_.proxy_resolution_service = |
| 16518 | std::make_unique<ProxyResolutionService>( |
| 16519 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 16520 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 16521 | nullptr, nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16522 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16523 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16524 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16525 | // Load a valid cert. Note, that this does not need to |
| 16526 | // be valid for proxy because the MockSSLClientSocket does |
| 16527 | // not actually verify it. But SpdySession will use this |
| 16528 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 16529 | ssl1.ssl_info.cert = |
| 16530 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 16531 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16532 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16533 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16534 | |
| 16535 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16536 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16537 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16538 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16539 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16540 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16541 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16542 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16543 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16544 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16545 | |
| 16546 | // Start the first transaction to set up the SpdySession |
| 16547 | HttpRequestInfo request1; |
| 16548 | request1.method = "GET"; |
| 16549 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16550 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16551 | request1.traffic_annotation = |
| 16552 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16553 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16554 | TestCompletionCallback callback1; |
| 16555 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16556 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16557 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16558 | data1.RunUntilPaused(); |
| 16559 | base::RunLoop().RunUntilIdle(); |
| 16560 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16561 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16562 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16563 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16564 | |
| 16565 | // Now, start the HTTP request |
| 16566 | HttpRequestInfo request2; |
| 16567 | request2.method = "GET"; |
| 16568 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16569 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16570 | request2.traffic_annotation = |
| 16571 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16572 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16573 | TestCompletionCallback callback2; |
| 16574 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16575 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16576 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16577 | |
| 16578 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16579 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16580 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16581 | } |
| 16582 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16583 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 16584 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 16585 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 16586 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16587 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16588 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16589 | |
| 16590 | MockRead reads1[] = { |
| 16591 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 16592 | }; |
| 16593 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16594 | SequencedSocketData data1(reads1, base::span<MockWrite>()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16595 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16596 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16597 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16598 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16599 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16600 | }; |
| 16601 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16602 | spdy::SpdySerializedFrame resp2( |
| 16603 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16604 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16605 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16606 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 16607 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16608 | }; |
| 16609 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16610 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16611 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16612 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16613 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16614 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16615 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16616 | |
| 16617 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16618 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16619 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16620 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16621 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16622 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16623 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16624 | |
| 16625 | // Start the first transaction to set up the SpdySession and verify that |
| 16626 | // connection was closed. |
| 16627 | HttpRequestInfo request1; |
| 16628 | request1.method = "GET"; |
| 16629 | request1.url = GURL(https_url); |
| 16630 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16631 | request1.traffic_annotation = |
| 16632 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16633 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16634 | TestCompletionCallback callback1; |
| 16635 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16636 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16637 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16638 | |
| 16639 | // Now, start the second request and make sure it succeeds. |
| 16640 | HttpRequestInfo request2; |
| 16641 | request2.method = "GET"; |
| 16642 | request2.url = GURL(https_url); |
| 16643 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16644 | request2.traffic_annotation = |
| 16645 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16646 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16647 | TestCompletionCallback callback2; |
| 16648 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16649 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16650 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16651 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16652 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16653 | } |
| 16654 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16655 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16656 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16657 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16658 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16659 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16660 | |
| 16661 | // Use two different hosts with different IPs so they don't get pooled. |
| 16662 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 16663 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16664 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16665 | |
| 16666 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16667 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16668 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16669 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16670 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16671 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16672 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16673 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16674 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16675 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16676 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16677 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16678 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16679 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16680 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16681 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16682 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16683 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16684 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16685 | }; |
| 16686 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16687 | // Use a separate test instance for the separate SpdySession that will be |
| 16688 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16689 | SpdyTestUtil spdy_util_2; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16690 | SequencedSocketData spdy1_data(spdy1_reads, spdy1_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 16691 | session_deps_.socket_factory->AddSocketDataProvider(&spdy1_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16692 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16693 | spdy::SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16694 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16695 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16696 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16697 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16698 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16699 | spdy_util_2.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16700 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16701 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16702 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16703 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16704 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16705 | }; |
| 16706 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16707 | SequencedSocketData spdy2_data(spdy2_reads, spdy2_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 16708 | session_deps_.socket_factory->AddSocketDataProvider(&spdy2_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16709 | |
| 16710 | MockWrite http_write[] = { |
| 16711 | MockWrite("GET / HTTP/1.1\r\n" |
| 16712 | "Host: www.a.com\r\n" |
| 16713 | "Connection: keep-alive\r\n\r\n"), |
| 16714 | }; |
| 16715 | |
| 16716 | MockRead http_read[] = { |
| 16717 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16718 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 16719 | MockRead("Content-Length: 6\r\n\r\n"), |
| 16720 | MockRead("hello!"), |
| 16721 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16722 | StaticSocketDataProvider http_data(http_read, http_write); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16723 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16724 | |
| 16725 | HostPortPair host_port_pair_a("www.a.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16726 | SpdySessionKey spdy_session_key_a( |
| 16727 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16728 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16729 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16730 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16731 | |
| 16732 | TestCompletionCallback callback; |
| 16733 | HttpRequestInfo request1; |
| 16734 | request1.method = "GET"; |
| 16735 | request1.url = GURL("https://www.a.com/"); |
| 16736 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16737 | request1.traffic_annotation = |
| 16738 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16739 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16740 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16741 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16742 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16743 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16744 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16745 | |
| 16746 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16747 | ASSERT_TRUE(response); |
| 16748 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16749 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16750 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16751 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16752 | |
| 16753 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16754 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16755 | EXPECT_EQ("hello!", response_data); |
| 16756 | trans.reset(); |
| 16757 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16758 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16759 | |
| 16760 | HostPortPair host_port_pair_b("www.b.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16761 | SpdySessionKey spdy_session_key_b( |
| 16762 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16763 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16764 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16765 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16766 | HttpRequestInfo request2; |
| 16767 | request2.method = "GET"; |
| 16768 | request2.url = GURL("https://www.b.com/"); |
| 16769 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16770 | request2.traffic_annotation = |
| 16771 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16772 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16773 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16774 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16775 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16776 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16777 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16778 | |
| 16779 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16780 | ASSERT_TRUE(response); |
| 16781 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16782 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16783 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16784 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16785 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16786 | EXPECT_EQ("hello!", response_data); |
| 16787 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16788 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16789 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16790 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16791 | |
| 16792 | HostPortPair host_port_pair_a1("www.a.com", 80); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16793 | SpdySessionKey spdy_session_key_a1( |
| 16794 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16795 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16796 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16797 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16798 | HttpRequestInfo request3; |
| 16799 | request3.method = "GET"; |
| 16800 | request3.url = GURL("http://www.a.com/"); |
| 16801 | request3.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16802 | request3.traffic_annotation = |
| 16803 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16804 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16805 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16806 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16807 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16808 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16809 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16810 | |
| 16811 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16812 | ASSERT_TRUE(response); |
| 16813 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16814 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 16815 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16816 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16817 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16818 | EXPECT_EQ("hello!", response_data); |
| 16819 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16820 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16821 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16822 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16823 | } |
| 16824 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16825 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16826 | HttpRequestInfo request; |
| 16827 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16828 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16829 | request.traffic_annotation = |
| 16830 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16831 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16832 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16833 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16834 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16835 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16836 | StaticSocketDataProvider data; |
| 16837 | data.set_connect_data(mock_connect); |
| 16838 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16839 | |
| 16840 | TestCompletionCallback callback; |
| 16841 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16842 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16843 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16844 | |
| 16845 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16846 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16847 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16848 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16849 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16850 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16851 | |
| 16852 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16853 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16854 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16855 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16856 | |
| 16857 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16858 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16859 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16860 | } |
| 16861 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16862 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16863 | HttpRequestInfo request; |
| 16864 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16865 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16866 | request.traffic_annotation = |
| 16867 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16868 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16869 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16870 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16871 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16872 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16873 | StaticSocketDataProvider data; |
| 16874 | data.set_connect_data(mock_connect); |
| 16875 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16876 | |
| 16877 | TestCompletionCallback callback; |
| 16878 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16879 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16880 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16881 | |
| 16882 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16883 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16884 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16885 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16886 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16887 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16888 | |
| 16889 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16890 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16891 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16892 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16893 | |
| 16894 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16895 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16896 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16897 | } |
| 16898 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16899 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16900 | HttpRequestInfo request; |
| 16901 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16902 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16903 | request.traffic_annotation = |
| 16904 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16905 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16906 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16907 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16908 | |
| 16909 | MockWrite data_writes[] = { |
| 16910 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16911 | }; |
| 16912 | MockRead data_reads[] = { |
| 16913 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16914 | }; |
| 16915 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16916 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16917 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16918 | |
| 16919 | TestCompletionCallback callback; |
| 16920 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16921 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16922 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16923 | |
| 16924 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16925 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16926 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16927 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16928 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16929 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16930 | } |
| 16931 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16932 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16933 | HttpRequestInfo request; |
| 16934 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16935 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16936 | request.traffic_annotation = |
| 16937 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16938 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16939 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16940 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16941 | |
| 16942 | MockWrite data_writes[] = { |
| 16943 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 16944 | }; |
| 16945 | MockRead data_reads[] = { |
| 16946 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16947 | }; |
| 16948 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16949 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16950 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16951 | |
| 16952 | TestCompletionCallback callback; |
| 16953 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16954 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16955 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16956 | |
| 16957 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16958 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16959 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16960 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16961 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16962 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16963 | } |
| 16964 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16965 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16966 | HttpRequestInfo request; |
| 16967 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16968 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16969 | request.traffic_annotation = |
| 16970 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16971 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16972 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16973 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16974 | |
| 16975 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16976 | MockWrite( |
| 16977 | "GET / HTTP/1.1\r\n" |
| 16978 | "Host: www.example.org\r\n" |
| 16979 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16980 | }; |
| 16981 | MockRead data_reads[] = { |
| 16982 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16983 | }; |
| 16984 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16985 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16986 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16987 | |
| 16988 | TestCompletionCallback callback; |
| 16989 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16990 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16991 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16992 | |
| 16993 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16994 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16995 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16996 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16997 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16998 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16999 | } |
| 17000 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17001 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17002 | HttpRequestInfo request; |
| 17003 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17004 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17005 | request.traffic_annotation = |
| 17006 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17007 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17008 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17009 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17010 | |
| 17011 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17012 | MockWrite( |
| 17013 | "GET / HTTP/1.1\r\n" |
| 17014 | "Host: www.example.org\r\n" |
| 17015 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17016 | }; |
| 17017 | MockRead data_reads[] = { |
| 17018 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 17019 | }; |
| 17020 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17021 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17022 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17023 | |
| 17024 | TestCompletionCallback callback; |
| 17025 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17026 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17027 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17028 | |
| 17029 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17030 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17031 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17032 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17033 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17034 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 17035 | } |
| 17036 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17037 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17038 | HttpRequestInfo request; |
| 17039 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17040 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17041 | request.extra_headers.SetHeader("X-Foo", "bar"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17042 | request.traffic_annotation = |
| 17043 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17044 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17045 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17046 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17047 | |
| 17048 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17049 | MockWrite( |
| 17050 | "GET / HTTP/1.1\r\n" |
| 17051 | "Host: www.example.org\r\n" |
| 17052 | "Connection: keep-alive\r\n" |
| 17053 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17054 | }; |
| 17055 | MockRead data_reads[] = { |
| 17056 | MockRead("HTTP/1.1 200 OK\r\n" |
| 17057 | "Content-Length: 5\r\n\r\n" |
| 17058 | "hello"), |
| 17059 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 17060 | }; |
| 17061 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17062 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17063 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17064 | |
| 17065 | TestCompletionCallback callback; |
| 17066 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17067 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17068 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17069 | |
| 17070 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17071 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17072 | |
| 17073 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17074 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17075 | std::string foo; |
| 17076 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 17077 | EXPECT_EQ("bar", foo); |
| 17078 | } |
| 17079 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17080 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 17081 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17082 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17083 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17084 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17085 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17086 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17087 | |
| 17088 | // Set up SSL request. |
| 17089 | |
| 17090 | HttpRequestInfo ssl_request; |
| 17091 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17092 | ssl_request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17093 | ssl_request.traffic_annotation = |
| 17094 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17095 | |
| 17096 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17097 | MockWrite( |
| 17098 | "GET / HTTP/1.1\r\n" |
| 17099 | "Host: www.example.org\r\n" |
| 17100 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17101 | }; |
| 17102 | MockRead ssl_reads[] = { |
| 17103 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17104 | MockRead("Content-Length: 11\r\n\r\n"), |
| 17105 | MockRead("hello world"), |
| 17106 | MockRead(SYNCHRONOUS, OK), |
| 17107 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17108 | StaticSocketDataProvider ssl_data(ssl_reads, ssl_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17109 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 17110 | |
| 17111 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17112 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17113 | |
| 17114 | // Set up HTTP request. |
| 17115 | |
| 17116 | HttpRequestInfo http_request; |
| 17117 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17118 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17119 | http_request.traffic_annotation = |
| 17120 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17121 | |
| 17122 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17123 | MockWrite( |
| 17124 | "GET / HTTP/1.1\r\n" |
| 17125 | "Host: www.example.org\r\n" |
| 17126 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17127 | }; |
| 17128 | MockRead http_reads[] = { |
| 17129 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17130 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17131 | MockRead("falafel"), |
| 17132 | MockRead(SYNCHRONOUS, OK), |
| 17133 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17134 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17135 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17136 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17137 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17138 | |
| 17139 | // Start the SSL request. |
| 17140 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17141 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17142 | ASSERT_EQ(ERR_IO_PENDING, |
| 17143 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 17144 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17145 | |
| 17146 | // Start the HTTP request. Pool should stall. |
| 17147 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17148 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17149 | ASSERT_EQ(ERR_IO_PENDING, |
| 17150 | http_trans.Start(&http_request, http_callback.callback(), |
| 17151 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17152 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17153 | |
| 17154 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17155 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17156 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17157 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17158 | EXPECT_EQ("hello world", response_data); |
| 17159 | |
| 17160 | // The SSL socket should automatically be closed, so the HTTP request can |
| 17161 | // start. |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 17162 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17163 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17164 | |
| 17165 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17166 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17167 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17168 | EXPECT_EQ("falafel", response_data); |
| 17169 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17170 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17171 | } |
| 17172 | |
| 17173 | // Tests that when a SSL connection is established but there's no corresponding |
| 17174 | // request that needs it, the new socket is closed if the transport socket pool |
| 17175 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17176 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17177 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17178 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17179 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17180 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17181 | |
| 17182 | // Set up an ssl request. |
| 17183 | |
| 17184 | HttpRequestInfo ssl_request; |
| 17185 | ssl_request.method = "GET"; |
| 17186 | ssl_request.url = GURL("https://www.foopy.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17187 | ssl_request.traffic_annotation = |
| 17188 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17189 | |
| 17190 | // No data will be sent on the SSL socket. |
| 17191 | StaticSocketDataProvider ssl_data; |
| 17192 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 17193 | |
| 17194 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17195 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17196 | |
| 17197 | // Set up HTTP request. |
| 17198 | |
| 17199 | HttpRequestInfo http_request; |
| 17200 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17201 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17202 | http_request.traffic_annotation = |
| 17203 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17204 | |
| 17205 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17206 | MockWrite( |
| 17207 | "GET / HTTP/1.1\r\n" |
| 17208 | "Host: www.example.org\r\n" |
| 17209 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17210 | }; |
| 17211 | MockRead http_reads[] = { |
| 17212 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17213 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17214 | MockRead("falafel"), |
| 17215 | MockRead(SYNCHRONOUS, OK), |
| 17216 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17217 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17218 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17219 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17220 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17221 | |
| 17222 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 17223 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 17224 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 17225 | http_stream_factory->PreconnectStreams(1, ssl_request); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 17226 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17227 | |
| 17228 | // Start the HTTP request. Pool should stall. |
| 17229 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17230 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17231 | ASSERT_EQ(ERR_IO_PENDING, |
| 17232 | http_trans.Start(&http_request, http_callback.callback(), |
| 17233 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17234 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17235 | |
| 17236 | // The SSL connection will automatically be closed once the connection is |
| 17237 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17238 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17239 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17240 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17241 | EXPECT_EQ("falafel", response_data); |
| 17242 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17243 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17244 | } |
| 17245 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17246 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17247 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17248 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17249 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17250 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17251 | |
| 17252 | HttpRequestInfo request; |
| 17253 | request.method = "POST"; |
| 17254 | request.url = GURL("http://www.foo.com/"); |
| 17255 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17256 | request.traffic_annotation = |
| 17257 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17258 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17259 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17260 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17261 | // Send headers successfully, but get an error while sending the body. |
| 17262 | MockWrite data_writes[] = { |
| 17263 | MockWrite("POST / HTTP/1.1\r\n" |
| 17264 | "Host: www.foo.com\r\n" |
| 17265 | "Connection: keep-alive\r\n" |
| 17266 | "Content-Length: 3\r\n\r\n"), |
| 17267 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17268 | }; |
| 17269 | |
| 17270 | MockRead data_reads[] = { |
| 17271 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17272 | MockRead("hello world"), |
| 17273 | MockRead(SYNCHRONOUS, OK), |
| 17274 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17275 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17276 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17277 | |
| 17278 | TestCompletionCallback callback; |
| 17279 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17280 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17281 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17282 | |
| 17283 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17284 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17285 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17286 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17287 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17288 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17289 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17290 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17291 | |
| 17292 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17293 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17294 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17295 | EXPECT_EQ("hello world", response_data); |
| 17296 | } |
| 17297 | |
| 17298 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 17299 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17300 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17301 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17302 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17303 | MockWrite data_writes[] = { |
| 17304 | MockWrite("GET / HTTP/1.1\r\n" |
| 17305 | "Host: www.foo.com\r\n" |
| 17306 | "Connection: keep-alive\r\n\r\n"), |
| 17307 | MockWrite("POST / HTTP/1.1\r\n" |
| 17308 | "Host: www.foo.com\r\n" |
| 17309 | "Connection: keep-alive\r\n" |
| 17310 | "Content-Length: 3\r\n\r\n"), |
| 17311 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17312 | }; |
| 17313 | |
| 17314 | MockRead data_reads[] = { |
| 17315 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 17316 | "Content-Length: 14\r\n\r\n"), |
| 17317 | MockRead("first response"), |
| 17318 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 17319 | "Content-Length: 15\r\n\r\n"), |
| 17320 | MockRead("second response"), |
| 17321 | MockRead(SYNCHRONOUS, OK), |
| 17322 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17323 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17324 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17325 | |
| 17326 | TestCompletionCallback callback; |
| 17327 | HttpRequestInfo request1; |
| 17328 | request1.method = "GET"; |
| 17329 | request1.url = GURL("http://www.foo.com/"); |
| 17330 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17331 | request1.traffic_annotation = |
| 17332 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17333 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17334 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17335 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17336 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17337 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17338 | |
| 17339 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17340 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17341 | |
| 17342 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17343 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17344 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17345 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17346 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 17347 | |
| 17348 | std::string response_data1; |
| 17349 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17350 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17351 | EXPECT_EQ("first response", response_data1); |
| 17352 | // Delete the transaction to release the socket back into the socket pool. |
| 17353 | trans1.reset(); |
| 17354 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17355 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17356 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17357 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17358 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17359 | |
| 17360 | HttpRequestInfo request2; |
| 17361 | request2.method = "POST"; |
| 17362 | request2.url = GURL("http://www.foo.com/"); |
| 17363 | request2.upload_data_stream = &upload_data_stream; |
| 17364 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17365 | request2.traffic_annotation = |
| 17366 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17367 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17368 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17369 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17370 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17371 | |
| 17372 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17373 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17374 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17375 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17376 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17377 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17378 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17379 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 17380 | |
| 17381 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17382 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17383 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17384 | EXPECT_EQ("second response", response_data2); |
| 17385 | } |
| 17386 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17387 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17388 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17389 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17390 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17391 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17392 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17393 | |
| 17394 | HttpRequestInfo request; |
| 17395 | request.method = "POST"; |
| 17396 | request.url = GURL("http://www.foo.com/"); |
| 17397 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17398 | request.traffic_annotation = |
| 17399 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17400 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17401 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17402 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17403 | // Send headers successfully, but get an error while sending the body. |
| 17404 | MockWrite data_writes[] = { |
| 17405 | MockWrite("POST / HTTP/1.1\r\n" |
| 17406 | "Host: www.foo.com\r\n" |
| 17407 | "Connection: keep-alive\r\n" |
| 17408 | "Content-Length: 3\r\n\r\n" |
| 17409 | "fo"), |
| 17410 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17411 | }; |
| 17412 | |
| 17413 | MockRead data_reads[] = { |
| 17414 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17415 | MockRead("hello world"), |
| 17416 | MockRead(SYNCHRONOUS, OK), |
| 17417 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17418 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17419 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17420 | |
| 17421 | TestCompletionCallback callback; |
| 17422 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17423 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17424 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17425 | |
| 17426 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17427 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17428 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17429 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17430 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17431 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17432 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17433 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17434 | |
| 17435 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17436 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17437 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17438 | EXPECT_EQ("hello world", response_data); |
| 17439 | } |
| 17440 | |
| 17441 | // This tests the more common case than the previous test, where headers and |
| 17442 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17443 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17444 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17445 | |
| 17446 | HttpRequestInfo request; |
| 17447 | request.method = "POST"; |
| 17448 | request.url = GURL("http://www.foo.com/"); |
| 17449 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17450 | request.traffic_annotation = |
| 17451 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17452 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17453 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17454 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17455 | // Send headers successfully, but get an error while sending the body. |
| 17456 | MockWrite data_writes[] = { |
| 17457 | MockWrite("POST / HTTP/1.1\r\n" |
| 17458 | "Host: www.foo.com\r\n" |
| 17459 | "Connection: keep-alive\r\n" |
| 17460 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17461 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17462 | }; |
| 17463 | |
| 17464 | MockRead data_reads[] = { |
| 17465 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17466 | MockRead("hello world"), |
| 17467 | MockRead(SYNCHRONOUS, OK), |
| 17468 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17469 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17470 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17471 | |
| 17472 | TestCompletionCallback callback; |
| 17473 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17474 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17475 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17476 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 17477 | // they can't be merged with the body in a single send. Not currently |
| 17478 | // necessary since a chunked body is never merged with headers, but this makes |
| 17479 | // the test more future proof. |
| 17480 | base::RunLoop().RunUntilIdle(); |
| 17481 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17482 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17483 | |
| 17484 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17485 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17486 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17487 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17488 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17489 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17490 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17491 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17492 | |
| 17493 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17494 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17495 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17496 | EXPECT_EQ("hello world", response_data); |
| 17497 | } |
| 17498 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17499 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17500 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17501 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17502 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17503 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17504 | |
| 17505 | HttpRequestInfo request; |
| 17506 | request.method = "POST"; |
| 17507 | request.url = GURL("http://www.foo.com/"); |
| 17508 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17509 | request.traffic_annotation = |
| 17510 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17511 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17512 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17513 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17514 | |
| 17515 | MockWrite data_writes[] = { |
| 17516 | MockWrite("POST / HTTP/1.1\r\n" |
| 17517 | "Host: www.foo.com\r\n" |
| 17518 | "Connection: keep-alive\r\n" |
| 17519 | "Content-Length: 3\r\n\r\n"), |
| 17520 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17521 | }; |
| 17522 | |
| 17523 | MockRead data_reads[] = { |
| 17524 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17525 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17526 | MockRead("hello world"), |
| 17527 | MockRead(SYNCHRONOUS, OK), |
| 17528 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17529 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17530 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17531 | |
| 17532 | TestCompletionCallback callback; |
| 17533 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17534 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17535 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17536 | |
| 17537 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17538 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17539 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17540 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17541 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17542 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17543 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17544 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17545 | |
| 17546 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17547 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17548 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17549 | EXPECT_EQ("hello world", response_data); |
| 17550 | } |
| 17551 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17552 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17553 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17554 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17555 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17556 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17557 | |
| 17558 | HttpRequestInfo request; |
| 17559 | request.method = "POST"; |
| 17560 | request.url = GURL("http://www.foo.com/"); |
| 17561 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17562 | request.traffic_annotation = |
| 17563 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17564 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17565 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17566 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17567 | // Send headers successfully, but get an error while sending the body. |
| 17568 | MockWrite data_writes[] = { |
| 17569 | MockWrite("POST / HTTP/1.1\r\n" |
| 17570 | "Host: www.foo.com\r\n" |
| 17571 | "Connection: keep-alive\r\n" |
| 17572 | "Content-Length: 3\r\n\r\n"), |
| 17573 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17574 | }; |
| 17575 | |
| 17576 | MockRead data_reads[] = { |
| 17577 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 17578 | MockRead("hello world"), |
| 17579 | MockRead(SYNCHRONOUS, OK), |
| 17580 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17581 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17582 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17583 | |
| 17584 | TestCompletionCallback callback; |
| 17585 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17586 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17587 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17588 | |
| 17589 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17590 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17591 | } |
| 17592 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17593 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17594 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17595 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17596 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17597 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17598 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17599 | |
| 17600 | HttpRequestInfo request; |
| 17601 | request.method = "POST"; |
| 17602 | request.url = GURL("http://www.foo.com/"); |
| 17603 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17604 | request.traffic_annotation = |
| 17605 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17606 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17607 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17608 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17609 | // Send headers successfully, but get an error while sending the body. |
| 17610 | MockWrite data_writes[] = { |
| 17611 | MockWrite("POST / HTTP/1.1\r\n" |
| 17612 | "Host: www.foo.com\r\n" |
| 17613 | "Connection: keep-alive\r\n" |
| 17614 | "Content-Length: 3\r\n\r\n"), |
| 17615 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17616 | }; |
| 17617 | |
| 17618 | MockRead data_reads[] = { |
| 17619 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17620 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 17621 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 17622 | MockRead("Content-Length: 0\r\n\r\n"), |
| 17623 | MockRead(SYNCHRONOUS, OK), |
| 17624 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17625 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17626 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17627 | |
| 17628 | TestCompletionCallback callback; |
| 17629 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17630 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17631 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17632 | |
| 17633 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17634 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17635 | } |
| 17636 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17637 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17638 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17639 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17640 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17641 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17642 | |
| 17643 | HttpRequestInfo request; |
| 17644 | request.method = "POST"; |
| 17645 | request.url = GURL("http://www.foo.com/"); |
| 17646 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17647 | request.traffic_annotation = |
| 17648 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17649 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17650 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17651 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17652 | // Send headers successfully, but get an error while sending the body. |
| 17653 | MockWrite data_writes[] = { |
| 17654 | MockWrite("POST / HTTP/1.1\r\n" |
| 17655 | "Host: www.foo.com\r\n" |
| 17656 | "Connection: keep-alive\r\n" |
| 17657 | "Content-Length: 3\r\n\r\n"), |
| 17658 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17659 | }; |
| 17660 | |
| 17661 | MockRead data_reads[] = { |
| 17662 | MockRead("HTTP 0.9 rocks!"), |
| 17663 | MockRead(SYNCHRONOUS, OK), |
| 17664 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17665 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17666 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17667 | |
| 17668 | TestCompletionCallback callback; |
| 17669 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17670 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17671 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17672 | |
| 17673 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17674 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17675 | } |
| 17676 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17677 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17678 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17679 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17680 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17681 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17682 | |
| 17683 | HttpRequestInfo request; |
| 17684 | request.method = "POST"; |
| 17685 | request.url = GURL("http://www.foo.com/"); |
| 17686 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17687 | request.traffic_annotation = |
| 17688 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17689 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17690 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17691 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17692 | // Send headers successfully, but get an error while sending the body. |
| 17693 | MockWrite data_writes[] = { |
| 17694 | MockWrite("POST / HTTP/1.1\r\n" |
| 17695 | "Host: www.foo.com\r\n" |
| 17696 | "Connection: keep-alive\r\n" |
| 17697 | "Content-Length: 3\r\n\r\n"), |
| 17698 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17699 | }; |
| 17700 | |
| 17701 | MockRead data_reads[] = { |
| 17702 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 17703 | MockRead(SYNCHRONOUS, OK), |
| 17704 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17705 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17706 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17707 | |
| 17708 | TestCompletionCallback callback; |
| 17709 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17710 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17711 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17712 | |
| 17713 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17714 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17715 | } |
| 17716 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17717 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17718 | |
| 17719 | namespace { |
| 17720 | |
| 17721 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
| 17722 | headers->SetHeader("Connection", "Upgrade"); |
| 17723 | headers->SetHeader("Upgrade", "websocket"); |
| 17724 | headers->SetHeader("Origin", "http://www.example.org"); |
| 17725 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17726 | } |
| 17727 | |
| 17728 | } // namespace |
| 17729 | |
| 17730 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17731 | for (bool secure : {true, false}) { |
| 17732 | MockWrite data_writes[] = { |
| 17733 | MockWrite("GET / HTTP/1.1\r\n" |
| 17734 | "Host: www.example.org\r\n" |
| 17735 | "Connection: Upgrade\r\n" |
| 17736 | "Upgrade: websocket\r\n" |
| 17737 | "Origin: http://www.example.org\r\n" |
| 17738 | "Sec-WebSocket-Version: 13\r\n" |
| 17739 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17740 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17741 | "client_max_window_bits\r\n\r\n")}; |
| 17742 | |
| 17743 | MockRead data_reads[] = { |
| 17744 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17745 | "Upgrade: websocket\r\n" |
| 17746 | "Connection: Upgrade\r\n" |
| 17747 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
| 17748 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17749 | StaticSocketDataProvider data(data_reads, data_writes); |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17750 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17751 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17752 | if (secure) |
| 17753 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17754 | |
| 17755 | HttpRequestInfo request; |
| 17756 | request.method = "GET"; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17757 | request.url = |
| 17758 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 17759 | AddWebSocketHeaders(&request.extra_headers); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17760 | request.traffic_annotation = |
| 17761 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17762 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17763 | TestWebSocketHandshakeStreamCreateHelper |
| 17764 | websocket_handshake_stream_create_helper; |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17765 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17766 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17767 | HttpNetworkTransaction trans(LOW, session.get()); |
| 17768 | trans.SetWebSocketHandshakeStreamCreateHelper( |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17769 | &websocket_handshake_stream_create_helper); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17770 | |
| 17771 | TestCompletionCallback callback; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17772 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17773 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17774 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17775 | const HttpStreamRequest* stream_request = trans.stream_request_.get(); |
| 17776 | ASSERT_TRUE(stream_request); |
| 17777 | EXPECT_EQ(&websocket_handshake_stream_create_helper, |
| 17778 | stream_request->websocket_handshake_stream_create_helper()); |
| 17779 | |
| 17780 | rv = callback.WaitForResult(); |
| 17781 | EXPECT_THAT(rv, IsOk()); |
| 17782 | |
| 17783 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 17784 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17785 | } |
| 17786 | } |
| 17787 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17788 | // Verify that proxy headers are not sent to the destination server when |
| 17789 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17790 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17791 | HttpRequestInfo request; |
| 17792 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17793 | request.url = GURL("wss://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17794 | request.traffic_annotation = |
| 17795 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17796 | AddWebSocketHeaders(&request.extra_headers); |
| 17797 | |
| 17798 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17799 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17800 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17801 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17802 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17803 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17804 | |
| 17805 | // Since a proxy is configured, try to establish a tunnel. |
| 17806 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17807 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17808 | "Host: www.example.org:443\r\n" |
| 17809 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17810 | |
| 17811 | // After calling trans->RestartWithAuth(), this is the request we should |
| 17812 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17813 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17814 | "Host: www.example.org:443\r\n" |
| 17815 | "Proxy-Connection: keep-alive\r\n" |
| 17816 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17817 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17818 | MockWrite("GET / HTTP/1.1\r\n" |
| 17819 | "Host: www.example.org\r\n" |
| 17820 | "Connection: Upgrade\r\n" |
| 17821 | "Upgrade: websocket\r\n" |
| 17822 | "Origin: http://www.example.org\r\n" |
| 17823 | "Sec-WebSocket-Version: 13\r\n" |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17824 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17825 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17826 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17827 | |
| 17828 | // The proxy responds to the connect with a 407, using a persistent |
| 17829 | // connection. |
| 17830 | MockRead data_reads[] = { |
| 17831 | // No credentials. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17832 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 17833 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 17834 | "Content-Length: 0\r\n" |
| 17835 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17836 | |
| 17837 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17838 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17839 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17840 | "Upgrade: websocket\r\n" |
| 17841 | "Connection: Upgrade\r\n" |
| 17842 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17843 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17844 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17845 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17846 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17847 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17848 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17849 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17850 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17851 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17852 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17853 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17854 | &websocket_stream_create_helper); |
| 17855 | |
| 17856 | { |
| 17857 | TestCompletionCallback callback; |
| 17858 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17859 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17860 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17861 | |
| 17862 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17863 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17864 | } |
| 17865 | |
| 17866 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17867 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17868 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17869 | EXPECT_EQ(407, response->headers->response_code()); |
| 17870 | |
| 17871 | { |
| 17872 | TestCompletionCallback callback; |
| 17873 | |
| 17874 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 17875 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17876 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17877 | |
| 17878 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17879 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17880 | } |
| 17881 | |
| 17882 | response = trans->GetResponseInfo(); |
| 17883 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17884 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17885 | |
| 17886 | EXPECT_EQ(101, response->headers->response_code()); |
| 17887 | |
| 17888 | trans.reset(); |
| 17889 | session->CloseAllConnections(); |
| 17890 | } |
| 17891 | |
| 17892 | // Verify that proxy headers are not sent to the destination server when |
| 17893 | // establishing a tunnel for an insecure WebSocket connection. |
| 17894 | // This requires the authentication info to be injected into the auth cache |
| 17895 | // due to crbug.com/395064 |
| 17896 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17897 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17898 | HttpRequestInfo request; |
| 17899 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17900 | request.url = GURL("ws://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17901 | request.traffic_annotation = |
| 17902 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17903 | AddWebSocketHeaders(&request.extra_headers); |
| 17904 | |
| 17905 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17906 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17907 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17908 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17909 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17910 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17911 | |
| 17912 | MockWrite data_writes[] = { |
| 17913 | // Try to establish a tunnel for the WebSocket connection, with |
| 17914 | // credentials. Because WebSockets have a separate set of socket pools, |
| 17915 | // they cannot and will not use the same TCP/IP connection as the |
| 17916 | // preflight HTTP request. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17917 | MockWrite("CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 17918 | "Host: www.example.org:80\r\n" |
| 17919 | "Proxy-Connection: keep-alive\r\n" |
| 17920 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17921 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17922 | MockWrite("GET / HTTP/1.1\r\n" |
| 17923 | "Host: www.example.org\r\n" |
| 17924 | "Connection: Upgrade\r\n" |
| 17925 | "Upgrade: websocket\r\n" |
| 17926 | "Origin: http://www.example.org\r\n" |
| 17927 | "Sec-WebSocket-Version: 13\r\n" |
| 17928 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17929 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17930 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17931 | |
| 17932 | MockRead data_reads[] = { |
| 17933 | // HTTP CONNECT with credentials. |
| 17934 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17935 | |
| 17936 | // WebSocket connection established inside tunnel. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17937 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17938 | "Upgrade: websocket\r\n" |
| 17939 | "Connection: Upgrade\r\n" |
| 17940 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17941 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17942 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17943 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17944 | |
| 17945 | session->http_auth_cache()->Add( |
| 17946 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 17947 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 17948 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17949 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17950 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17951 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17952 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17953 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17954 | &websocket_stream_create_helper); |
| 17955 | |
| 17956 | TestCompletionCallback callback; |
| 17957 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17958 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17959 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17960 | |
| 17961 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17962 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17963 | |
| 17964 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17965 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17966 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17967 | |
| 17968 | EXPECT_EQ(101, response->headers->response_code()); |
| 17969 | |
| 17970 | trans.reset(); |
| 17971 | session->CloseAllConnections(); |
| 17972 | } |
| 17973 | |
Matt Menke | 1d6093e3 | 2019-03-22 17:33:43 | [diff] [blame] | 17974 | // WebSockets over QUIC is not supported, including over QUIC proxies. |
| 17975 | TEST_F(HttpNetworkTransactionTest, WebSocketNotSentOverQuicProxy) { |
| 17976 | for (bool secure : {true, false}) { |
| 17977 | SCOPED_TRACE(secure); |
| 17978 | session_deps_.proxy_resolution_service = |
| 17979 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17980 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 17981 | session_deps_.enable_quic = true; |
| 17982 | |
| 17983 | HttpRequestInfo request; |
| 17984 | request.url = |
| 17985 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 17986 | AddWebSocketHeaders(&request.extra_headers); |
| 17987 | request.traffic_annotation = |
| 17988 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 17989 | |
| 17990 | TestWebSocketHandshakeStreamCreateHelper |
| 17991 | websocket_handshake_stream_create_helper; |
| 17992 | |
| 17993 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17994 | HttpNetworkTransaction trans(LOW, session.get()); |
| 17995 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 17996 | &websocket_handshake_stream_create_helper); |
| 17997 | |
| 17998 | TestCompletionCallback callback; |
| 17999 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18000 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18001 | |
| 18002 | rv = callback.WaitForResult(); |
| 18003 | EXPECT_THAT(rv, IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 18004 | } |
| 18005 | } |
| 18006 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18007 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 18008 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18009 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18010 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18011 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18012 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18013 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18014 | |
| 18015 | HttpRequestInfo request; |
| 18016 | request.method = "POST"; |
| 18017 | request.url = GURL("http://www.foo.com/"); |
| 18018 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18019 | request.traffic_annotation = |
| 18020 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18021 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18022 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18023 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18024 | MockWrite data_writes[] = { |
| 18025 | MockWrite("POST / HTTP/1.1\r\n" |
| 18026 | "Host: www.foo.com\r\n" |
| 18027 | "Connection: keep-alive\r\n" |
| 18028 | "Content-Length: 3\r\n\r\n"), |
| 18029 | MockWrite("foo"), |
| 18030 | }; |
| 18031 | |
| 18032 | MockRead data_reads[] = { |
| 18033 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18034 | MockRead(SYNCHRONOUS, OK), |
| 18035 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18036 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18037 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18038 | |
| 18039 | TestCompletionCallback callback; |
| 18040 | |
| 18041 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18042 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18043 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18044 | |
| 18045 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18046 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18047 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18048 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18049 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18050 | } |
| 18051 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18052 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18053 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18054 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18055 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18056 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18057 | |
| 18058 | HttpRequestInfo request; |
| 18059 | request.method = "POST"; |
| 18060 | request.url = GURL("http://www.foo.com/"); |
| 18061 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18062 | request.traffic_annotation = |
| 18063 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18064 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18065 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18066 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18067 | MockWrite data_writes[] = { |
| 18068 | MockWrite("POST / HTTP/1.1\r\n" |
| 18069 | "Host: www.foo.com\r\n" |
| 18070 | "Connection: keep-alive\r\n" |
| 18071 | "Content-Length: 3\r\n\r\n"), |
| 18072 | MockWrite("foo"), |
| 18073 | }; |
| 18074 | |
| 18075 | MockRead data_reads[] = { |
| 18076 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 18077 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18078 | MockRead(SYNCHRONOUS, OK), |
| 18079 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18080 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18081 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18082 | |
| 18083 | TestCompletionCallback callback; |
| 18084 | |
| 18085 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18086 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18087 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18088 | |
| 18089 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18090 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18091 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18092 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18093 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18094 | } |
| 18095 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18096 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18097 | ChunkedUploadDataStream upload_data_stream(0); |
| 18098 | |
| 18099 | HttpRequestInfo request; |
| 18100 | request.method = "POST"; |
| 18101 | request.url = GURL("http://www.foo.com/"); |
| 18102 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18103 | request.traffic_annotation = |
| 18104 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18105 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18106 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18107 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18108 | // Send headers successfully, but get an error while sending the body. |
| 18109 | MockWrite data_writes[] = { |
| 18110 | MockWrite("POST / HTTP/1.1\r\n" |
| 18111 | "Host: www.foo.com\r\n" |
| 18112 | "Connection: keep-alive\r\n" |
| 18113 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 18114 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 18115 | }; |
| 18116 | |
| 18117 | MockRead data_reads[] = { |
| 18118 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18119 | MockRead(SYNCHRONOUS, OK), |
| 18120 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18121 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18122 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18123 | |
| 18124 | TestCompletionCallback callback; |
| 18125 | |
| 18126 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18127 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18128 | |
| 18129 | base::RunLoop().RunUntilIdle(); |
| 18130 | upload_data_stream.AppendData("f", 1, false); |
| 18131 | |
| 18132 | base::RunLoop().RunUntilIdle(); |
| 18133 | upload_data_stream.AppendData("oo", 2, true); |
| 18134 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18135 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18136 | |
| 18137 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18138 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18139 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18140 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18141 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18142 | } |
| 18143 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18144 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 18145 | const std::string& accept_encoding, |
| 18146 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18147 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18148 | bool should_match) { |
| 18149 | HttpRequestInfo request; |
| 18150 | request.method = "GET"; |
| 18151 | request.url = GURL("http://www.foo.com/"); |
| 18152 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 18153 | accept_encoding); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18154 | request.traffic_annotation = |
| 18155 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18156 | |
| 18157 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 18158 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18159 | // Send headers successfully, but get an error while sending the body. |
| 18160 | MockWrite data_writes[] = { |
| 18161 | MockWrite("GET / HTTP/1.1\r\n" |
| 18162 | "Host: www.foo.com\r\n" |
| 18163 | "Connection: keep-alive\r\n" |
| 18164 | "Accept-Encoding: "), |
| 18165 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 18166 | }; |
| 18167 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18168 | std::string response_code = "200 OK"; |
| 18169 | std::string extra; |
| 18170 | if (!location.empty()) { |
| 18171 | response_code = "301 Redirect\r\nLocation: "; |
| 18172 | response_code.append(location); |
| 18173 | } |
| 18174 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18175 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18176 | MockRead("HTTP/1.0 "), |
| 18177 | MockRead(response_code.data()), |
| 18178 | MockRead("\r\nContent-Encoding: "), |
| 18179 | MockRead(content_encoding.data()), |
| 18180 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18181 | MockRead(SYNCHRONOUS, OK), |
| 18182 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18183 | StaticSocketDataProvider data(data_reads, data_writes); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18184 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 18185 | |
| 18186 | TestCompletionCallback callback; |
| 18187 | |
| 18188 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18189 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18190 | |
| 18191 | rv = callback.WaitForResult(); |
| 18192 | if (should_match) { |
| 18193 | EXPECT_THAT(rv, IsOk()); |
| 18194 | } else { |
| 18195 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 18196 | } |
| 18197 | } |
| 18198 | |
| 18199 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18200 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18201 | } |
| 18202 | |
| 18203 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18204 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 18205 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18206 | } |
| 18207 | |
| 18208 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 18209 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18210 | "", false); |
| 18211 | } |
| 18212 | |
| 18213 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 18214 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 18215 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18216 | } |
| 18217 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18218 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 18219 | ProxyConfig proxy_config; |
| 18220 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18221 | proxy_config.set_pac_mandatory(true); |
| 18222 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18223 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18224 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18225 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Bence Béky | 8f9d7d395 | 2017-10-09 19:58:04 | [diff] [blame] | 18226 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18227 | |
| 18228 | HttpRequestInfo request; |
| 18229 | request.method = "GET"; |
| 18230 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18231 | request.traffic_annotation = |
| 18232 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18233 | |
| 18234 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18235 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18236 | |
| 18237 | TestCompletionCallback callback; |
| 18238 | |
| 18239 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18240 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18241 | EXPECT_THAT(callback.WaitForResult(), |
| 18242 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18243 | } |
| 18244 | |
| 18245 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 18246 | ProxyConfig proxy_config; |
| 18247 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18248 | proxy_config.set_pac_mandatory(true); |
| 18249 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 18250 | new MockAsyncProxyResolverFactory(false); |
| 18251 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18252 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18253 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18254 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18255 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18256 | HttpRequestInfo request; |
| 18257 | request.method = "GET"; |
| 18258 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18259 | request.traffic_annotation = |
| 18260 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18261 | |
| 18262 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18263 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18264 | |
| 18265 | TestCompletionCallback callback; |
| 18266 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18267 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18268 | |
| 18269 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 18270 | ERR_FAILED, &resolver); |
| 18271 | EXPECT_THAT(callback.WaitForResult(), |
| 18272 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18273 | } |
| 18274 | |
| 18275 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18276 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18277 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18278 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18279 | session_deps_.enable_quic = false; |
| 18280 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18281 | |
| 18282 | HttpRequestInfo request; |
| 18283 | request.method = "GET"; |
| 18284 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18285 | request.traffic_annotation = |
| 18286 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18287 | |
| 18288 | TestCompletionCallback callback; |
| 18289 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18290 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18291 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18292 | |
| 18293 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 18294 | } |
| 18295 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18296 | //----------------------------------------------------------------------------- |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18297 | // Reporting tests |
| 18298 | |
| 18299 | #if BUILDFLAG(ENABLE_REPORTING) |
| 18300 | class HttpNetworkTransactionReportingTest : public HttpNetworkTransactionTest { |
| 18301 | protected: |
| 18302 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18303 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18304 | auto test_reporting_context = std::make_unique<TestReportingContext>( |
| 18305 | &clock_, &tick_clock_, ReportingPolicy()); |
| 18306 | test_reporting_context_ = test_reporting_context.get(); |
| 18307 | session_deps_.reporting_service = |
| 18308 | ReportingService::CreateForTesting(std::move(test_reporting_context)); |
| 18309 | } |
| 18310 | |
| 18311 | TestReportingContext* reporting_context() const { |
| 18312 | return test_reporting_context_; |
| 18313 | } |
| 18314 | |
| 18315 | void clear_reporting_service() { |
| 18316 | session_deps_.reporting_service.reset(); |
| 18317 | test_reporting_context_ = nullptr; |
| 18318 | } |
| 18319 | |
| 18320 | // Makes an HTTPS request that should install a valid Reporting policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18321 | void RequestPolicy(CertStatus cert_status = 0) { |
| 18322 | HttpRequestInfo request; |
| 18323 | request.method = "GET"; |
| 18324 | request.url = GURL(url_); |
| 18325 | request.traffic_annotation = |
| 18326 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18327 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18328 | MockWrite data_writes[] = { |
| 18329 | MockWrite("GET / HTTP/1.1\r\n" |
| 18330 | "Host: www.example.org\r\n" |
| 18331 | "Connection: keep-alive\r\n\r\n"), |
| 18332 | }; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18333 | MockRead data_reads[] = { |
| 18334 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18335 | MockRead("Report-To: {\"group\": \"nel\", \"max_age\": 86400, " |
| 18336 | "\"endpoints\": [{\"url\": " |
| 18337 | "\"https://www.example.org/upload/\"}]}\r\n"), |
| 18338 | MockRead("\r\n"), |
| 18339 | MockRead("hello world"), |
| 18340 | MockRead(SYNCHRONOUS, OK), |
| 18341 | }; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18342 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18343 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18344 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18345 | |
| 18346 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18347 | if (request.url.SchemeIsCryptographic()) { |
| 18348 | ssl.ssl_info.cert = |
| 18349 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18350 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18351 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18352 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18353 | } |
| 18354 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18355 | TestCompletionCallback callback; |
| 18356 | auto session = CreateSession(&session_deps_); |
| 18357 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18358 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18359 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18360 | } |
| 18361 | |
| 18362 | protected: |
| 18363 | std::string url_ = "https://www.example.org/"; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18364 | |
| 18365 | private: |
| 18366 | TestReportingContext* test_reporting_context_; |
| 18367 | }; |
| 18368 | |
| 18369 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18370 | DontProcessReportToHeaderNoService) { |
| 18371 | base::HistogramTester histograms; |
| 18372 | clear_reporting_service(); |
| 18373 | RequestPolicy(); |
| 18374 | histograms.ExpectBucketCount( |
| 18375 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18376 | ReportingHeaderParser::HeaderOutcome::DISCARDED_NO_REPORTING_SERVICE, 1); |
| 18377 | } |
| 18378 | |
| 18379 | TEST_F(HttpNetworkTransactionReportingTest, DontProcessReportToHeaderHttp) { |
| 18380 | base::HistogramTester histograms; |
| 18381 | url_ = "http://www.example.org/"; |
| 18382 | RequestPolicy(); |
| 18383 | histograms.ExpectBucketCount( |
| 18384 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18385 | ReportingHeaderParser::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18386 | } |
| 18387 | |
| 18388 | TEST_F(HttpNetworkTransactionReportingTest, ProcessReportToHeaderHttps) { |
| 18389 | RequestPolicy(); |
| 18390 | std::vector<const ReportingClient*> clients; |
| 18391 | reporting_context()->cache()->GetClients(&clients); |
| 18392 | ASSERT_EQ(1u, clients.size()); |
| 18393 | const auto* client = clients[0]; |
| 18394 | EXPECT_EQ(url::Origin::Create(GURL("https://www.example.org/")), |
| 18395 | client->origin); |
| 18396 | EXPECT_EQ(GURL("https://www.example.org/upload/"), client->endpoint); |
| 18397 | EXPECT_EQ("nel", client->group); |
| 18398 | } |
| 18399 | |
| 18400 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18401 | DontProcessReportToHeaderInvalidHttps) { |
| 18402 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18403 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18404 | RequestPolicy(cert_status); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18405 | histograms.ExpectBucketCount( |
| 18406 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18407 | ReportingHeaderParser::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, 1); |
| 18408 | } |
| 18409 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 18410 | |
| 18411 | //----------------------------------------------------------------------------- |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18412 | // Network Error Logging tests |
| 18413 | |
| 18414 | #if BUILDFLAG(ENABLE_REPORTING) |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18415 | namespace { |
| 18416 | |
| 18417 | const char kUserAgent[] = "Mozilla/1.0"; |
| 18418 | const char kReferrer[] = "https://www.referrer.org/"; |
| 18419 | |
| 18420 | } // namespace |
| 18421 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18422 | class HttpNetworkTransactionNetworkErrorLoggingTest |
| 18423 | : public HttpNetworkTransactionTest { |
| 18424 | protected: |
| 18425 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18426 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18427 | auto network_error_logging_service = |
| 18428 | std::make_unique<TestNetworkErrorLoggingService>(); |
| 18429 | test_network_error_logging_service_ = network_error_logging_service.get(); |
| 18430 | session_deps_.network_error_logging_service = |
| 18431 | std::move(network_error_logging_service); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18432 | |
| 18433 | extra_headers_.SetHeader("User-Agent", kUserAgent); |
| 18434 | extra_headers_.SetHeader("Referer", kReferrer); |
| 18435 | |
| 18436 | request_.method = "GET"; |
| 18437 | request_.url = GURL(url_); |
| 18438 | request_.extra_headers = extra_headers_; |
| 18439 | request_.reporting_upload_depth = reporting_upload_depth_; |
| 18440 | request_.traffic_annotation = |
| 18441 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18442 | } |
| 18443 | |
| 18444 | TestNetworkErrorLoggingService* network_error_logging_service() const { |
| 18445 | return test_network_error_logging_service_; |
| 18446 | } |
| 18447 | |
| 18448 | void clear_network_error_logging_service() { |
| 18449 | session_deps_.network_error_logging_service.reset(); |
| 18450 | test_network_error_logging_service_ = nullptr; |
| 18451 | } |
| 18452 | |
| 18453 | // Makes an HTTPS request that should install a valid NEL policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18454 | void RequestPolicy(CertStatus cert_status = 0) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18455 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18456 | MockWrite data_writes[] = { |
| 18457 | MockWrite("GET / HTTP/1.1\r\n" |
| 18458 | "Host: www.example.org\r\n" |
| 18459 | "Connection: keep-alive\r\n"), |
| 18460 | MockWrite(ASYNC, extra_header_string.data(), |
| 18461 | extra_header_string.size()), |
| 18462 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18463 | MockRead data_reads[] = { |
| 18464 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18465 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 18466 | MockRead("\r\n"), |
| 18467 | MockRead("hello world"), |
| 18468 | MockRead(SYNCHRONOUS, OK), |
| 18469 | }; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18470 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18471 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18472 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18473 | |
| 18474 | SSLSocketDataProvider ssl(ASYNC, OK); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18475 | if (request_.url.SchemeIsCryptographic()) { |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18476 | ssl.ssl_info.cert = |
| 18477 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18478 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18479 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18480 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18481 | } |
| 18482 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18483 | TestCompletionCallback callback; |
| 18484 | auto session = CreateSession(&session_deps_); |
| 18485 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18486 | int rv = trans.Start(&request_, callback.callback(), NetLogWithSource()); |
| 18487 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18488 | |
| 18489 | std::string response_data; |
| 18490 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 18491 | EXPECT_EQ("hello world", response_data); |
| 18492 | } |
| 18493 | |
| 18494 | void CheckReport(size_t index, |
| 18495 | int status_code, |
| 18496 | int error_type, |
| 18497 | IPAddress server_ip = IPAddress::IPv4Localhost()) { |
| 18498 | ASSERT_LT(index, network_error_logging_service()->errors().size()); |
| 18499 | |
| 18500 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18501 | network_error_logging_service()->errors()[index]; |
| 18502 | EXPECT_EQ(url_, error.uri); |
| 18503 | EXPECT_EQ(kReferrer, error.referrer); |
| 18504 | EXPECT_EQ(kUserAgent, error.user_agent); |
| 18505 | EXPECT_EQ(server_ip, error.server_ip); |
| 18506 | EXPECT_EQ("http/1.1", error.protocol); |
| 18507 | EXPECT_EQ("GET", error.method); |
| 18508 | EXPECT_EQ(status_code, error.status_code); |
| 18509 | EXPECT_EQ(error_type, error.type); |
| 18510 | EXPECT_EQ(0, error.reporting_upload_depth); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18511 | } |
| 18512 | |
| 18513 | protected: |
| 18514 | std::string url_ = "https://www.example.org/"; |
| 18515 | CertStatus cert_status_ = 0; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18516 | HttpRequestInfo request_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18517 | HttpRequestHeaders extra_headers_; |
| 18518 | int reporting_upload_depth_ = 0; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18519 | |
| 18520 | private: |
| 18521 | TestNetworkErrorLoggingService* test_network_error_logging_service_; |
| 18522 | }; |
| 18523 | |
| 18524 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18525 | DontProcessNelHeaderNoService) { |
| 18526 | base::HistogramTester histograms; |
| 18527 | clear_network_error_logging_service(); |
| 18528 | RequestPolicy(); |
| 18529 | histograms.ExpectBucketCount( |
| 18530 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18531 | NetworkErrorLoggingService::HeaderOutcome:: |
| 18532 | DISCARDED_NO_NETWORK_ERROR_LOGGING_SERVICE, |
| 18533 | 1); |
| 18534 | } |
| 18535 | |
| 18536 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18537 | DontProcessNelHeaderHttp) { |
| 18538 | base::HistogramTester histograms; |
| 18539 | url_ = "http://www.example.org/"; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18540 | request_.url = GURL(url_); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18541 | RequestPolicy(); |
| 18542 | histograms.ExpectBucketCount( |
| 18543 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18544 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18545 | } |
| 18546 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 18547 | // Don't set NEL policies received on a proxied connection. |
| 18548 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18549 | DontProcessNelHeaderProxy) { |
| 18550 | session_deps_.proxy_resolution_service = |
| 18551 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18552 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18553 | BoundTestNetLog log; |
| 18554 | session_deps_.net_log = log.bound().net_log(); |
| 18555 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18556 | |
| 18557 | HttpRequestInfo request; |
| 18558 | request.method = "GET"; |
| 18559 | request.url = GURL("https://www.example.org/"); |
| 18560 | request.traffic_annotation = |
| 18561 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18562 | |
| 18563 | // Since we have proxy, should try to establish tunnel. |
| 18564 | MockWrite data_writes1[] = { |
| 18565 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 18566 | "Host: www.example.org:443\r\n" |
| 18567 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 18568 | |
| 18569 | MockWrite("GET / HTTP/1.1\r\n" |
| 18570 | "Host: www.example.org\r\n" |
| 18571 | "Connection: keep-alive\r\n\r\n"), |
| 18572 | }; |
| 18573 | |
| 18574 | MockRead data_reads1[] = { |
| 18575 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 18576 | |
| 18577 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 18578 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 18579 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18580 | MockRead("Content-Length: 100\r\n\r\n"), |
| 18581 | MockRead(SYNCHRONOUS, OK), |
| 18582 | }; |
| 18583 | |
| 18584 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18585 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18586 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18587 | ssl.ssl_info.cert = |
| 18588 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18589 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 18590 | ssl.ssl_info.cert_status = 0; |
| 18591 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18592 | |
| 18593 | TestCompletionCallback callback1; |
| 18594 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18595 | |
| 18596 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
| 18597 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18598 | |
| 18599 | rv = callback1.WaitForResult(); |
| 18600 | EXPECT_THAT(rv, IsOk()); |
| 18601 | |
| 18602 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 18603 | ASSERT_TRUE(response); |
| 18604 | EXPECT_EQ(200, response->headers->response_code()); |
| 18605 | EXPECT_TRUE(response->was_fetched_via_proxy); |
| 18606 | |
| 18607 | // No NEL header was set. |
| 18608 | EXPECT_EQ(0u, network_error_logging_service()->headers().size()); |
| 18609 | } |
| 18610 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18611 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ProcessNelHeaderHttps) { |
| 18612 | RequestPolicy(); |
| 18613 | ASSERT_EQ(1u, network_error_logging_service()->headers().size()); |
| 18614 | const auto& header = network_error_logging_service()->headers()[0]; |
| 18615 | EXPECT_EQ(url::Origin::Create(GURL("https://www.example.org/")), |
| 18616 | header.origin); |
| 18617 | EXPECT_EQ(IPAddress::IPv4Localhost(), header.received_ip_address); |
| 18618 | EXPECT_EQ("{\"report_to\": \"nel\", \"max_age\": 86400}", header.value); |
| 18619 | } |
| 18620 | |
| 18621 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18622 | DontProcessNelHeaderInvalidHttps) { |
| 18623 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18624 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18625 | RequestPolicy(cert_status); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18626 | histograms.ExpectBucketCount( |
| 18627 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18628 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, |
| 18629 | 1); |
| 18630 | } |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18631 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18632 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, CreateReportSuccess) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18633 | RequestPolicy(); |
| 18634 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18635 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 18636 | } |
| 18637 | |
| 18638 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18639 | CreateReportErrorAfterStart) { |
| 18640 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18641 | auto trans = |
| 18642 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18643 | |
| 18644 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
| 18645 | StaticSocketDataProvider data; |
| 18646 | data.set_connect_data(mock_connect); |
| 18647 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18648 | |
| 18649 | TestCompletionCallback callback; |
| 18650 | |
| 18651 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18652 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 18653 | |
| 18654 | trans.reset(); |
| 18655 | |
| 18656 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18657 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 18658 | IPAddress() /* server_ip */); |
| 18659 | } |
| 18660 | |
| 18661 | // Same as above except the error is ASYNC |
| 18662 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18663 | CreateReportErrorAfterStartAsync) { |
| 18664 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18665 | auto trans = |
| 18666 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18667 | |
| 18668 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
| 18669 | StaticSocketDataProvider data; |
| 18670 | data.set_connect_data(mock_connect); |
| 18671 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18672 | |
| 18673 | TestCompletionCallback callback; |
| 18674 | |
| 18675 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18676 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 18677 | |
| 18678 | trans.reset(); |
| 18679 | |
| 18680 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18681 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 18682 | IPAddress() /* server_ip */); |
| 18683 | } |
| 18684 | |
| 18685 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18686 | CreateReportReadBodyError) { |
| 18687 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18688 | MockWrite data_writes[] = { |
| 18689 | MockWrite("GET / HTTP/1.1\r\n" |
| 18690 | "Host: www.example.org\r\n" |
| 18691 | "Connection: keep-alive\r\n"), |
| 18692 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18693 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18694 | MockRead data_reads[] = { |
| 18695 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18696 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 18697 | MockRead("hello world"), |
| 18698 | MockRead(SYNCHRONOUS, OK), |
| 18699 | }; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18700 | |
| 18701 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18702 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 18703 | |
| 18704 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18705 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18706 | |
| 18707 | // Log start time |
| 18708 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18709 | |
| 18710 | TestCompletionCallback callback; |
| 18711 | auto session = CreateSession(&session_deps_); |
| 18712 | auto trans = |
| 18713 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18714 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18715 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18716 | |
| 18717 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18718 | ASSERT_TRUE(response); |
| 18719 | |
| 18720 | EXPECT_TRUE(response->headers); |
| 18721 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 18722 | |
| 18723 | std::string response_data; |
| 18724 | rv = ReadTransaction(trans.get(), &response_data); |
| 18725 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 18726 | |
| 18727 | trans.reset(); |
| 18728 | |
| 18729 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18730 | |
| 18731 | CheckReport(0 /* index */, 200 /* status_code */, |
| 18732 | ERR_CONTENT_LENGTH_MISMATCH); |
| 18733 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18734 | network_error_logging_service()->errors()[0]; |
| 18735 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 18736 | } |
| 18737 | |
| 18738 | // Same as above except the final read is ASYNC. |
| 18739 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18740 | CreateReportReadBodyErrorAsync) { |
| 18741 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18742 | MockWrite data_writes[] = { |
| 18743 | MockWrite("GET / HTTP/1.1\r\n" |
| 18744 | "Host: www.example.org\r\n" |
| 18745 | "Connection: keep-alive\r\n"), |
| 18746 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18747 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18748 | MockRead data_reads[] = { |
| 18749 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18750 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 18751 | MockRead("hello world"), |
| 18752 | MockRead(ASYNC, OK), |
| 18753 | }; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18754 | |
| 18755 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18756 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 18757 | |
| 18758 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18759 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18760 | |
| 18761 | // Log start time |
| 18762 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18763 | |
| 18764 | TestCompletionCallback callback; |
| 18765 | auto session = CreateSession(&session_deps_); |
| 18766 | auto trans = |
| 18767 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18768 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18769 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18770 | |
| 18771 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18772 | ASSERT_TRUE(response); |
| 18773 | |
| 18774 | EXPECT_TRUE(response->headers); |
| 18775 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 18776 | |
| 18777 | std::string response_data; |
| 18778 | rv = ReadTransaction(trans.get(), &response_data); |
| 18779 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 18780 | |
| 18781 | trans.reset(); |
| 18782 | |
| 18783 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18784 | |
| 18785 | CheckReport(0 /* index */, 200 /* status_code */, |
| 18786 | ERR_CONTENT_LENGTH_MISMATCH); |
| 18787 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18788 | network_error_logging_service()->errors()[0]; |
| 18789 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 18790 | } |
| 18791 | |
| 18792 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18793 | CreateReportRestartWithAuth) { |
| 18794 | std::string extra_header_string = extra_headers_.ToString(); |
| 18795 | static const base::TimeDelta kSleepDuration = |
| 18796 | base::TimeDelta::FromMilliseconds(10); |
| 18797 | |
| 18798 | MockWrite data_writes1[] = { |
| 18799 | MockWrite("GET / HTTP/1.1\r\n" |
| 18800 | "Host: www.example.org\r\n" |
| 18801 | "Connection: keep-alive\r\n"), |
| 18802 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18803 | }; |
| 18804 | |
| 18805 | MockRead data_reads1[] = { |
| 18806 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 18807 | // Give a couple authenticate options (only the middle one is actually |
| 18808 | // supported). |
| 18809 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 18810 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 18811 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 18812 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18813 | // Large content-length -- won't matter, as connection will be reset. |
| 18814 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 18815 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 18816 | }; |
| 18817 | |
| 18818 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18819 | // be issuing -- the final header line contains the credentials. |
| 18820 | MockWrite data_writes2[] = { |
| 18821 | MockWrite("GET / HTTP/1.1\r\n" |
| 18822 | "Host: www.example.org\r\n" |
| 18823 | "Connection: keep-alive\r\n" |
| 18824 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 18825 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18826 | }; |
| 18827 | |
| 18828 | // Lastly, the server responds with the actual content. |
| 18829 | MockRead data_reads2[] = { |
| 18830 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 18831 | MockRead("hello world"), |
| 18832 | MockRead(SYNCHRONOUS, OK), |
| 18833 | }; |
| 18834 | |
| 18835 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18836 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 18837 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18838 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18839 | |
| 18840 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18841 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18842 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18843 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18844 | |
| 18845 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18846 | base::TimeTicks restart_time; |
| 18847 | |
| 18848 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18849 | auto trans = |
| 18850 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18851 | |
| 18852 | TestCompletionCallback callback1; |
| 18853 | |
| 18854 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18855 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18856 | |
| 18857 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18858 | |
| 18859 | TestCompletionCallback callback2; |
| 18860 | |
| 18861 | // Wait 10 ms then restart with auth |
| 18862 | FastForwardBy(kSleepDuration); |
| 18863 | restart_time = base::TimeTicks::Now(); |
| 18864 | rv = |
| 18865 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 18866 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18867 | |
| 18868 | std::string response_data; |
| 18869 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 18870 | EXPECT_EQ("hello world", response_data); |
| 18871 | |
| 18872 | trans.reset(); |
| 18873 | |
| 18874 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 18875 | // retry. Note that we don't report the error draining the body, as the first |
| 18876 | // request already generated a report for the auth challenge. |
| 18877 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 18878 | |
| 18879 | // Check error report contents |
| 18880 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 18881 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 18882 | |
| 18883 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 18884 | network_error_logging_service()->errors()[0]; |
| 18885 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 18886 | network_error_logging_service()->errors()[1]; |
| 18887 | |
| 18888 | // Sanity-check elapsed time values |
| 18889 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 18890 | // Check that the start time is refreshed when restarting with auth. |
| 18891 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 18892 | } |
| 18893 | |
| 18894 | // Same as above, except draining the body before restarting fails |
| 18895 | // asynchronously. |
| 18896 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18897 | CreateReportRestartWithAuthAsync) { |
| 18898 | std::string extra_header_string = extra_headers_.ToString(); |
| 18899 | static const base::TimeDelta kSleepDuration = |
| 18900 | base::TimeDelta::FromMilliseconds(10); |
| 18901 | |
| 18902 | MockWrite data_writes1[] = { |
| 18903 | MockWrite("GET / HTTP/1.1\r\n" |
| 18904 | "Host: www.example.org\r\n" |
| 18905 | "Connection: keep-alive\r\n"), |
| 18906 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18907 | }; |
| 18908 | |
| 18909 | MockRead data_reads1[] = { |
| 18910 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 18911 | // Give a couple authenticate options (only the middle one is actually |
| 18912 | // supported). |
| 18913 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 18914 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 18915 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 18916 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18917 | // Large content-length -- won't matter, as connection will be reset. |
| 18918 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 18919 | MockRead(ASYNC, ERR_FAILED), |
| 18920 | }; |
| 18921 | |
| 18922 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18923 | // be issuing -- the final header line contains the credentials. |
| 18924 | MockWrite data_writes2[] = { |
| 18925 | MockWrite("GET / HTTP/1.1\r\n" |
| 18926 | "Host: www.example.org\r\n" |
| 18927 | "Connection: keep-alive\r\n" |
| 18928 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 18929 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18930 | }; |
| 18931 | |
| 18932 | // Lastly, the server responds with the actual content. |
| 18933 | MockRead data_reads2[] = { |
| 18934 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 18935 | MockRead("hello world"), |
| 18936 | MockRead(SYNCHRONOUS, OK), |
| 18937 | }; |
| 18938 | |
| 18939 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18940 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 18941 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18942 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18943 | |
| 18944 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18945 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18946 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18947 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18948 | |
| 18949 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18950 | base::TimeTicks restart_time; |
| 18951 | |
| 18952 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18953 | auto trans = |
| 18954 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18955 | |
| 18956 | TestCompletionCallback callback1; |
| 18957 | |
| 18958 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18959 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18960 | |
| 18961 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18962 | |
| 18963 | TestCompletionCallback callback2; |
| 18964 | |
| 18965 | // Wait 10 ms then restart with auth |
| 18966 | FastForwardBy(kSleepDuration); |
| 18967 | restart_time = base::TimeTicks::Now(); |
| 18968 | rv = |
| 18969 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 18970 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18971 | |
| 18972 | std::string response_data; |
| 18973 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 18974 | EXPECT_EQ("hello world", response_data); |
| 18975 | |
| 18976 | trans.reset(); |
| 18977 | |
| 18978 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 18979 | // retry. Note that we don't report the error draining the body, as the first |
| 18980 | // request already generated a report for the auth challenge. |
| 18981 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 18982 | |
| 18983 | // Check error report contents |
| 18984 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 18985 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 18986 | |
| 18987 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 18988 | network_error_logging_service()->errors()[0]; |
| 18989 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 18990 | network_error_logging_service()->errors()[1]; |
| 18991 | |
| 18992 | // Sanity-check elapsed time values |
| 18993 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 18994 | // Check that the start time is refreshed when restarting with auth. |
| 18995 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 18996 | } |
| 18997 | |
| 18998 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18999 | CreateReportRetryKeepAliveConnectionReset) { |
| 19000 | std::string extra_header_string = extra_headers_.ToString(); |
| 19001 | MockWrite data_writes1[] = { |
| 19002 | MockWrite("GET / HTTP/1.1\r\n" |
| 19003 | "Host: www.example.org\r\n" |
| 19004 | "Connection: keep-alive\r\n"), |
| 19005 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 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 | }; |
| 19011 | |
| 19012 | MockRead data_reads1[] = { |
| 19013 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19014 | MockRead("hello"), |
| 19015 | // Connection is reset |
| 19016 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 19017 | }; |
| 19018 | |
| 19019 | // Successful retry |
| 19020 | MockRead data_reads2[] = { |
| 19021 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19022 | MockRead("world"), |
| 19023 | MockRead(ASYNC, OK), |
| 19024 | }; |
| 19025 | |
| 19026 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19027 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 19028 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19029 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19030 | |
| 19031 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 19032 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 19033 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 19034 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 19035 | |
| 19036 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19037 | auto trans1 = |
| 19038 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19039 | |
| 19040 | TestCompletionCallback callback1; |
| 19041 | |
| 19042 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 19043 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19044 | |
| 19045 | std::string response_data; |
| 19046 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19047 | EXPECT_EQ("hello", response_data); |
| 19048 | |
| 19049 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19050 | |
| 19051 | auto trans2 = |
| 19052 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19053 | |
| 19054 | TestCompletionCallback callback2; |
| 19055 | |
| 19056 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 19057 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19058 | |
| 19059 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19060 | EXPECT_EQ("world", response_data); |
| 19061 | |
| 19062 | trans1.reset(); |
| 19063 | trans2.reset(); |
| 19064 | |
| 19065 | // One OK report from first request, then a ERR_CONNECTION_RESET report from |
| 19066 | // the second request, then an OK report from the successful retry. |
| 19067 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19068 | |
| 19069 | // Check error report contents |
| 19070 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19071 | CheckReport(1 /* index */, 0 /* status_code */, ERR_CONNECTION_RESET); |
| 19072 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 19073 | } |
| 19074 | |
| 19075 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19076 | CreateReportRetryKeepAlive408) { |
| 19077 | std::string extra_header_string = extra_headers_.ToString(); |
| 19078 | MockWrite data_writes1[] = { |
| 19079 | MockWrite("GET / HTTP/1.1\r\n" |
| 19080 | "Host: www.example.org\r\n" |
| 19081 | "Connection: keep-alive\r\n"), |
| 19082 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 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 | }; |
| 19088 | |
| 19089 | MockRead data_reads1[] = { |
| 19090 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19091 | MockRead("hello"), |
| 19092 | // 408 Request Timeout |
| 19093 | MockRead(SYNCHRONOUS, |
| 19094 | "HTTP/1.1 408 Request Timeout\r\n" |
| 19095 | "Connection: Keep-Alive\r\n" |
| 19096 | "Content-Length: 6\r\n\r\n" |
| 19097 | "Pickle"), |
| 19098 | }; |
| 19099 | |
| 19100 | // Successful retry |
| 19101 | MockRead data_reads2[] = { |
| 19102 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19103 | MockRead("world"), |
| 19104 | MockRead(ASYNC, OK), |
| 19105 | }; |
| 19106 | |
| 19107 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19108 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 19109 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19110 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19111 | |
| 19112 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 19113 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 19114 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 19115 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 19116 | |
| 19117 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19118 | auto trans1 = |
| 19119 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19120 | |
| 19121 | TestCompletionCallback callback1; |
| 19122 | |
| 19123 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 19124 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19125 | |
| 19126 | std::string response_data; |
| 19127 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19128 | EXPECT_EQ("hello", response_data); |
| 19129 | |
| 19130 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19131 | |
| 19132 | auto trans2 = |
| 19133 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19134 | |
| 19135 | TestCompletionCallback callback2; |
| 19136 | |
| 19137 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 19138 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19139 | |
| 19140 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19141 | EXPECT_EQ("world", response_data); |
| 19142 | |
| 19143 | trans1.reset(); |
| 19144 | trans2.reset(); |
| 19145 | |
| 19146 | // One 200 report from first request, then a 408 report from |
| 19147 | // the second request, then a 200 report from the successful retry. |
| 19148 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19149 | |
| 19150 | // Check error report contents |
| 19151 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19152 | CheckReport(1 /* index */, 408 /* status_code */, OK); |
| 19153 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 19154 | } |
| 19155 | |
| 19156 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19157 | CreateReportRetry421WithoutConnectionPooling) { |
| 19158 | // Two hosts resolve to the same IP address. |
| 19159 | const std::string ip_addr = "1.2.3.4"; |
| 19160 | IPAddress ip; |
| 19161 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 19162 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 19163 | |
| 19164 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
| 19165 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 19166 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 19167 | |
| 19168 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19169 | |
| 19170 | // Two requests on the first connection. |
| 19171 | spdy::SpdySerializedFrame req1( |
| 19172 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 19173 | spdy_util_.UpdateWithStreamDestruction(1); |
| 19174 | spdy::SpdySerializedFrame req2( |
| 19175 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 19176 | spdy::SpdySerializedFrame rst( |
| 19177 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
| 19178 | MockWrite writes1[] = { |
| 19179 | CreateMockWrite(req1, 0), |
| 19180 | CreateMockWrite(req2, 3), |
| 19181 | CreateMockWrite(rst, 6), |
| 19182 | }; |
| 19183 | |
| 19184 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 19185 | spdy::SpdySerializedFrame resp1( |
| 19186 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 19187 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 19188 | spdy::SpdyHeaderBlock response_headers; |
| 19189 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 19190 | spdy::SpdySerializedFrame resp2( |
| 19191 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 19192 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 19193 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 19194 | |
| 19195 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 19196 | SequencedSocketData data1(connect1, reads1, writes1); |
| 19197 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19198 | |
| 19199 | AddSSLSocketData(); |
| 19200 | |
| 19201 | // Retry the second request on a second connection. |
| 19202 | SpdyTestUtil spdy_util2; |
| 19203 | spdy::SpdySerializedFrame req3( |
| 19204 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 19205 | MockWrite writes2[] = { |
| 19206 | CreateMockWrite(req3, 0), |
| 19207 | }; |
| 19208 | |
| 19209 | spdy::SpdySerializedFrame resp3( |
| 19210 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 19211 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 19212 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 19213 | MockRead(ASYNC, 0, 3)}; |
| 19214 | |
| 19215 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 19216 | SequencedSocketData data2(connect2, reads2, writes2); |
| 19217 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19218 | |
| 19219 | AddSSLSocketData(); |
| 19220 | |
| 19221 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 19222 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 19223 | HostPortPair("mail.example.com", 443), base::nullopt); |
| 19224 | EXPECT_THAT(rv, IsOk()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19225 | |
| 19226 | HttpRequestInfo request1; |
| 19227 | request1.method = "GET"; |
| 19228 | request1.url = GURL("https://www.example.org/"); |
| 19229 | request1.load_flags = 0; |
| 19230 | request1.traffic_annotation = |
| 19231 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19232 | auto trans1 = |
| 19233 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19234 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 19235 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19236 | rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 19237 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19238 | |
| 19239 | const HttpResponseInfo* response = trans1->GetResponseInfo(); |
| 19240 | ASSERT_TRUE(response); |
| 19241 | ASSERT_TRUE(response->headers); |
| 19242 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19243 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19244 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19245 | std::string response_data; |
| 19246 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19247 | EXPECT_EQ("hello!", response_data); |
| 19248 | |
| 19249 | trans1.reset(); |
| 19250 | |
| 19251 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19252 | |
| 19253 | HttpRequestInfo request2; |
| 19254 | request2.method = "GET"; |
| 19255 | request2.url = GURL("https://mail.example.org/"); |
| 19256 | request2.load_flags = 0; |
| 19257 | request2.traffic_annotation = |
| 19258 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19259 | auto trans2 = |
| 19260 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19261 | |
| 19262 | BoundTestNetLog log; |
| 19263 | rv = trans2->Start(&request2, callback.callback(), log.bound()); |
| 19264 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19265 | |
| 19266 | response = trans2->GetResponseInfo(); |
| 19267 | ASSERT_TRUE(response); |
| 19268 | ASSERT_TRUE(response->headers); |
| 19269 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19270 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19271 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19272 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19273 | EXPECT_EQ("hello!", response_data); |
| 19274 | |
| 19275 | trans2.reset(); |
| 19276 | |
| 19277 | // One 200 report from the first request, then a 421 report from the |
| 19278 | // second request, then a 200 report from the successful retry. |
| 19279 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19280 | |
| 19281 | // Check error report contents |
| 19282 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 19283 | network_error_logging_service()->errors()[0]; |
| 19284 | EXPECT_EQ(GURL("https://www.example.org/"), error1.uri); |
| 19285 | EXPECT_TRUE(error1.referrer.is_empty()); |
| 19286 | EXPECT_EQ("", error1.user_agent); |
| 19287 | EXPECT_EQ(ip, error1.server_ip); |
| 19288 | EXPECT_EQ("h2", error1.protocol); |
| 19289 | EXPECT_EQ("GET", error1.method); |
| 19290 | EXPECT_EQ(200, error1.status_code); |
| 19291 | EXPECT_EQ(OK, error1.type); |
| 19292 | EXPECT_EQ(0, error1.reporting_upload_depth); |
| 19293 | |
| 19294 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 19295 | network_error_logging_service()->errors()[1]; |
| 19296 | EXPECT_EQ(GURL("https://mail.example.org/"), error2.uri); |
| 19297 | EXPECT_TRUE(error2.referrer.is_empty()); |
| 19298 | EXPECT_EQ("", error2.user_agent); |
| 19299 | EXPECT_EQ(ip, error2.server_ip); |
| 19300 | EXPECT_EQ("h2", error2.protocol); |
| 19301 | EXPECT_EQ("GET", error2.method); |
| 19302 | EXPECT_EQ(421, error2.status_code); |
| 19303 | EXPECT_EQ(OK, error2.type); |
| 19304 | EXPECT_EQ(0, error2.reporting_upload_depth); |
| 19305 | |
| 19306 | const NetworkErrorLoggingService::RequestDetails& error3 = |
| 19307 | network_error_logging_service()->errors()[2]; |
| 19308 | EXPECT_EQ(GURL("https://mail.example.org/"), error3.uri); |
| 19309 | EXPECT_TRUE(error3.referrer.is_empty()); |
| 19310 | EXPECT_EQ("", error3.user_agent); |
| 19311 | EXPECT_EQ(ip, error3.server_ip); |
| 19312 | EXPECT_EQ("h2", error3.protocol); |
| 19313 | EXPECT_EQ("GET", error3.method); |
| 19314 | EXPECT_EQ(200, error3.status_code); |
| 19315 | EXPECT_EQ(OK, error3.type); |
| 19316 | EXPECT_EQ(0, error3.reporting_upload_depth); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19317 | } |
| 19318 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19319 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19320 | CreateReportCancelAfterStart) { |
| 19321 | StaticSocketDataProvider data; |
| 19322 | data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING)); |
| 19323 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19324 | |
| 19325 | TestCompletionCallback callback; |
| 19326 | auto session = CreateSession(&session_deps_); |
| 19327 | auto trans = |
| 19328 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19329 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19330 | EXPECT_EQ(rv, ERR_IO_PENDING); |
| 19331 | |
| 19332 | // Cancel after start. |
| 19333 | trans.reset(); |
| 19334 | |
| 19335 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19336 | CheckReport(0 /* index */, 0 /* status_code */, ERR_ABORTED, |
| 19337 | IPAddress() /* server_ip */); |
| 19338 | } |
| 19339 | |
| 19340 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19341 | CreateReportCancelBeforeReadingBody) { |
| 19342 | std::string extra_header_string = extra_headers_.ToString(); |
| 19343 | MockWrite data_writes[] = { |
| 19344 | MockWrite("GET / HTTP/1.1\r\n" |
| 19345 | "Host: www.example.org\r\n" |
| 19346 | "Connection: keep-alive\r\n"), |
| 19347 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19348 | }; |
| 19349 | MockRead data_reads[] = { |
| 19350 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 19351 | MockRead("Content-Length: 100\r\n\r\n"), // Body is never read. |
| 19352 | }; |
| 19353 | |
| 19354 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19355 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19356 | |
| 19357 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19358 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19359 | |
| 19360 | TestCompletionCallback callback; |
| 19361 | auto session = CreateSession(&session_deps_); |
| 19362 | auto trans = |
| 19363 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19364 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19365 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19366 | |
| 19367 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19368 | ASSERT_TRUE(response); |
| 19369 | |
| 19370 | EXPECT_TRUE(response->headers); |
| 19371 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 19372 | |
| 19373 | // Cancel before reading the body. |
| 19374 | trans.reset(); |
| 19375 | |
| 19376 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19377 | CheckReport(0 /* index */, 200 /* status_code */, ERR_ABORTED); |
| 19378 | } |
| 19379 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19380 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportHttp) { |
| 19381 | base::HistogramTester histograms; |
| 19382 | RequestPolicy(); |
| 19383 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19384 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19385 | |
| 19386 | // Make HTTP request |
| 19387 | std::string extra_header_string = extra_headers_.ToString(); |
| 19388 | MockRead data_reads[] = { |
| 19389 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 19390 | MockRead("hello world"), |
| 19391 | MockRead(SYNCHRONOUS, OK), |
| 19392 | }; |
| 19393 | MockWrite data_writes[] = { |
| 19394 | MockWrite("GET / HTTP/1.1\r\n" |
| 19395 | "Host: www.example.org\r\n" |
| 19396 | "Connection: keep-alive\r\n"), |
| 19397 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19398 | }; |
| 19399 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19400 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19401 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19402 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19403 | // Insecure url |
| 19404 | url_ = "http://www.example.org/"; |
| 19405 | request_.url = GURL(url_); |
| 19406 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19407 | TestCompletionCallback callback; |
| 19408 | auto session = CreateSession(&session_deps_); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19409 | auto trans = |
| 19410 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19411 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19412 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19413 | |
| 19414 | std::string response_data; |
| 19415 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19416 | EXPECT_EQ("hello world", response_data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19417 | |
| 19418 | // Insecure request does not generate a report |
| 19419 | histograms.ExpectBucketCount( |
| 19420 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
Tsuyoshi Horo | 0b04223 | 2019-03-06 01:11:05 | [diff] [blame] | 19421 | NetworkErrorLoggingService::RequestOutcome::kDiscardedInsecureOrigin, 1); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19422 | |
| 19423 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19424 | } |
| 19425 | |
| 19426 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19427 | DontCreateReportHttpError) { |
| 19428 | base::HistogramTester histograms; |
| 19429 | RequestPolicy(); |
| 19430 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19431 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19432 | |
| 19433 | // Make HTTP request that fails |
| 19434 | MockRead data_reads[] = { |
| 19435 | MockRead("hello world"), |
| 19436 | MockRead(SYNCHRONOUS, OK), |
| 19437 | }; |
| 19438 | |
| 19439 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
| 19440 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19441 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19442 | url_ = "http://www.originwithoutpolicy.com:2000/"; |
| 19443 | request_.url = GURL(url_); |
| 19444 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19445 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19446 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19447 | auto trans = |
| 19448 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19449 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19450 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19451 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 19452 | |
| 19453 | // Insecure request does not generate a report, regardless of existence of a |
| 19454 | // policy for the origin. |
| 19455 | histograms.ExpectBucketCount( |
| 19456 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
Tsuyoshi Horo | 0b04223 | 2019-03-06 01:11:05 | [diff] [blame] | 19457 | NetworkErrorLoggingService::RequestOutcome::kDiscardedInsecureOrigin, 1); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19458 | |
| 19459 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19460 | } |
| 19461 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 19462 | // Don't report on proxy auth challenges, don't report if connecting through a |
| 19463 | // proxy. |
| 19464 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportProxy) { |
| 19465 | HttpRequestInfo request; |
| 19466 | request.method = "GET"; |
| 19467 | request.url = GURL("https://www.example.org/"); |
| 19468 | request.traffic_annotation = |
| 19469 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19470 | |
| 19471 | // Configure against proxy server "myproxy:70". |
| 19472 | session_deps_.proxy_resolution_service = |
| 19473 | ProxyResolutionService::CreateFixedFromPacResult( |
| 19474 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19475 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19476 | |
| 19477 | // Since we have proxy, should try to establish tunnel. |
| 19478 | MockWrite data_writes1[] = { |
| 19479 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19480 | "Host: www.example.org:443\r\n" |
| 19481 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 19482 | }; |
| 19483 | |
| 19484 | // The proxy responds to the connect with a 407, using a non-persistent |
| 19485 | // connection. |
| 19486 | MockRead data_reads1[] = { |
| 19487 | // No credentials. |
| 19488 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 19489 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 19490 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 19491 | }; |
| 19492 | |
| 19493 | MockWrite data_writes2[] = { |
| 19494 | // After calling trans->RestartWithAuth(), this is the request we should |
| 19495 | // be issuing -- the final header line contains the credentials. |
| 19496 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19497 | "Host: www.example.org:443\r\n" |
| 19498 | "Proxy-Connection: keep-alive\r\n" |
| 19499 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 19500 | |
| 19501 | MockWrite("GET / HTTP/1.1\r\n" |
| 19502 | "Host: www.example.org\r\n" |
| 19503 | "Connection: keep-alive\r\n\r\n"), |
| 19504 | }; |
| 19505 | |
| 19506 | MockRead data_reads2[] = { |
| 19507 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 19508 | |
| 19509 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19510 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 19511 | MockRead("Content-Length: 5\r\n\r\n"), |
| 19512 | MockRead(SYNCHRONOUS, "hello"), |
| 19513 | }; |
| 19514 | |
| 19515 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19516 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19517 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 19518 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19519 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19520 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19521 | |
| 19522 | TestCompletionCallback callback1; |
| 19523 | |
| 19524 | auto trans = |
| 19525 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19526 | |
| 19527 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
| 19528 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19529 | |
| 19530 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19531 | EXPECT_EQ(407, response->headers->response_code()); |
| 19532 | |
| 19533 | std::string response_data; |
| 19534 | rv = ReadTransaction(trans.get(), &response_data); |
| 19535 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
| 19536 | |
| 19537 | // No NEL report is generated for the 407. |
| 19538 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 19539 | |
| 19540 | TestCompletionCallback callback2; |
| 19541 | |
| 19542 | rv = |
| 19543 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 19544 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19545 | |
| 19546 | response = trans->GetResponseInfo(); |
| 19547 | EXPECT_EQ(200, response->headers->response_code()); |
| 19548 | |
| 19549 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19550 | EXPECT_EQ("hello", response_data); |
| 19551 | |
| 19552 | trans.reset(); |
| 19553 | |
| 19554 | // No NEL report is generated because we are behind a proxy. |
| 19555 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 19556 | } |
| 19557 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19558 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19559 | ReportContainsUploadDepth) { |
| 19560 | reporting_upload_depth_ = 7; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19561 | request_.reporting_upload_depth = reporting_upload_depth_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19562 | RequestPolicy(); |
| 19563 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19564 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19565 | network_error_logging_service()->errors()[0]; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19566 | EXPECT_EQ(7, error.reporting_upload_depth); |
| 19567 | } |
| 19568 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19569 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ReportElapsedTime) { |
| 19570 | std::string extra_header_string = extra_headers_.ToString(); |
| 19571 | static const base::TimeDelta kSleepDuration = |
| 19572 | base::TimeDelta::FromMilliseconds(10); |
| 19573 | |
| 19574 | std::vector<MockWrite> data_writes = { |
| 19575 | MockWrite(ASYNC, 0, |
| 19576 | "GET / HTTP/1.1\r\n" |
| 19577 | "Host: www.example.org\r\n" |
| 19578 | "Connection: keep-alive\r\n"), |
| 19579 | MockWrite(ASYNC, 1, extra_header_string.data()), |
| 19580 | }; |
| 19581 | |
| 19582 | std::vector<MockRead> data_reads = { |
| 19583 | // Write one byte of the status line, followed by a pause. |
| 19584 | MockRead(ASYNC, 2, "H"), |
| 19585 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 19586 | MockRead(ASYNC, 4, "TTP/1.1 200 OK\r\n\r\n"), |
| 19587 | MockRead(ASYNC, 5, "hello world"), |
| 19588 | MockRead(SYNCHRONOUS, OK, 6), |
| 19589 | }; |
| 19590 | |
| 19591 | SequencedSocketData data(data_reads, data_writes); |
| 19592 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19593 | |
| 19594 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19595 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19596 | |
| 19597 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19598 | |
| 19599 | auto trans = |
| 19600 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19601 | |
| 19602 | TestCompletionCallback callback; |
| 19603 | |
| 19604 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19605 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19606 | |
| 19607 | data.RunUntilPaused(); |
| 19608 | ASSERT_TRUE(data.IsPaused()); |
| 19609 | FastForwardBy(kSleepDuration); |
| 19610 | data.Resume(); |
| 19611 | |
| 19612 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19613 | |
| 19614 | std::string response_data; |
| 19615 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19616 | EXPECT_EQ("hello world", response_data); |
| 19617 | |
| 19618 | trans.reset(); |
| 19619 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19620 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19621 | |
| 19622 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19623 | |
| 19624 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19625 | network_error_logging_service()->errors()[0]; |
| 19626 | |
| 19627 | // Sanity-check elapsed time in error report |
| 19628 | EXPECT_EQ(kSleepDuration, error.elapsed_time); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19629 | } |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19630 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19631 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 19632 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 19633 | } // namespace net |